使用WebDriver 登录163邮箱
案例:登录163邮箱
1、新建一个WebElementUtil 类,该类主要用于封装API,即为页面控件常用的操作(比如说文本框输入值、下拉框操作、单选操作等等)
在此贴出此次用到的一些:
/**
* 浏览器操作(打开浏览器)
*/
public void openBrowser(WebDriver driver, String url){
driver.get(url);
driver.manage().window().maximize();
log.info(url + "该网址已经被打开"+"\n" );
}
// 文本框输入值操作
public void setBox( WebElement e, String content){
e.clear();
e.sendKeys(content);
log.info("控件" + "输入内容为:" + content +"\n");
}
// button 点击操作
public void buttonClick(WebElement e) {
if(this.buttonIsEnable(e)){
e.click();
}
}
2、新建一个类为 DriverToBrowser ,该类目的是为了打开浏览器操作,比如说打开IE 、FF、chrome 浏览器
import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class DriverToBrowser {
private static WebDriver driver;
public static WebDriver startDriver(int key){
switch(key) {
case 0:
//ͨ打开IE浏览器
File file =new File("C:/Program Files/Internet Explorer/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver",file.getAbsolutePath());
driver = new InternetExplorerDriver();
break;
case 1:
//打开火狐浏览器
driver = new FirefoxDriver();
break;
case 2:
// 打开chrome浏览器
driver = new ChromeDriver();
break;
}
return driver;
}
public static WebDriver getDriver(){
return driver;
}
}
3、新建一个Login 类,该类主要是为了打开 163邮箱,代码如下:
public class Login {
private static WebDriver driver;
String url = "http://mail.163.com" ;
String name = "";
String password = "";
LogUtil log = new LogUtil(Login.class);
WebElementUtil elementUtil = new WebElementUtil();
@Test
public void login() {
DriverToBrowser.startDriver(0);
driver = DriverToBrowser.getDriver();
elementUtil.openBrowser(driver, url);
elementUtil.waitImplicitly(driver, 3000);
elementUtil.switchToFrame(driver, driver.findElement(By.id("x-URS-iframe")));
WebElement nameElement = driver.findElement(By.name("email"));
elementUtil.setBox(nameElement, "*********");
WebElement passwordElement = driver.findElement(By.name("password"));
elementUtil.setBox(passwordElement, "*******");
WebElement buttonement = driver.findElement(By.id("dologin"));
elementUtil.buttonClick(buttonement);
elementUtil.waitImplicitly(driver, 3000);
}
@AfterTest
public void quit(){
elementUtil.closeBrowser(driver);
}
}
4、运行结果为:
使用WebDriver 登录163邮箱相关推荐
- [Python爬虫] Selenium实现自动登录163邮箱和Locating Elements介绍
前三篇文章介绍了安装过程和通过Selenium实现访问Firefox浏览器并自动搜索"Eastmount"关键字及截图的功能.而这篇文章主要简单介绍如何实现自动登录163邮箱,同时 ...
- python模拟qq空间登录_python selenium模拟登录163邮箱和QQ空间
最近在看python网络爬虫,于是我想自己写一个邮箱和QQ空间的自动登录的小程序, 下面以登录163邮箱和QQ空间和为例: 了解到在Web应用中经常会遇到frame/iframe 表单嵌套页面的应用, ...
- Python爬虫 Selenium实现自动登录163邮箱和Locating Elements介绍
Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门 https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6E ...
- Selenium WebDrive使用Edge浏览器模拟登录163邮箱
** Selenium WebDrive使用Edge浏览器模拟登录163邮箱(详细过程及代码) ** 1.首先要在pycharm中下载好Selenium 2.然后下载浏览器驱动这里是链接 (https ...
- [Python爬虫] Selenium实现自己主动登录163邮箱和Locating Elements介绍
前三篇文章介绍了安装过程和通过Selenium实现訪问Firefox浏览器并自己主动搜索"Eastmount"keyword及截图的功能.而这篇文章主要简介怎样实现 ...
- python浏览器自动化测试仪器_【松勤软件自动化测试】纯干货:基于Python+Selenium2登录163邮箱实例...
一.业务流程: 1.打开浏览器,自动填写用户名和密码,登录成功后跳转到相应的页面. 2.验证相应页面的url与给定的url是否一致,如果一致则测试通过,如果不一致,则不通过. 3.另外,在执行过程中如 ...
- java制作网易邮箱登录页面_Page Object实例(一) - Java + Selenium 登录163邮箱
Page Object 是什么: Page Object(selenium wiki)是Selenium2开始提供的一种代码设计模式. 其核心思想是把web页面的元素查找及操作和页面测试分离开. 这样 ...
- 用Python+Selenium来测试登录自动登录163邮箱
用Python+Selenium来测试登录自动登录163邮箱 1 准备条件 2 程序说明 3 代码 1 准备条件 ① windows系统(也许你是Linux,Mac,自行选择) ②安装了Anacond ...
- python3爬虫系列21之selenium自动化登录163邮箱并读取未读邮件内容
python3爬虫系列21之selenium自动化登录163邮箱并读取未读邮件内容 1.前言 前面在 python3爬虫系列20之反爬需要登录的网站三种处理方式中介绍的第三种方法,使用自动化测试工具s ...
- 安全邮箱是什么邮箱?怎么登录163邮箱?
安全邮箱是什么邮箱?怎么登录163邮箱?电子邮箱中,分为免费邮箱.vip邮箱.企业邮箱三大类别,从属性即可辨别出具体用途.通常日常办公,如果是5人以上的企业,可使用企业邮箱方便管理.个人日常办公可选择 ...
最新文章
- 《基于张量网络的机器学习入门》学习笔记2
- Chrome好用的插件
- Bash Shell中命令行选项/参数处理
- 【Hive】一次被分区条件和笛卡尔积制裁的经历
- java 根据类名示例化类_Java LocalDateTime类| atOffset()方法与示例
- 递归 与 动态规划 区别
- FAT32和NTFS的区别
- 基于K60/K66/LPC的HC-SR04超声波测距(附带代码)
- 大专java考试试题_专科—程序设计基础题库-java.doc
- 普通的测试员和牛逼的测试员有什么区别?完成这两次跨越,你也可以
- 如何实现一个HTML5 RPG游戏引擎——第五章,实现人物和人物特效
- halcon学习之颜色与纹理
- db2 springboot 整合_Spring boot Mybatis 整合(完整版)
- 智慧城市大数据分析系统解决方案
- [转帖]张汝京:告别中芯国际这10年
- 漫画 | 为什么程序猿996会猝死,而企业家007却不会?
- android检测ibeacon电量,Android检测IBeacon热点的方法
- android仿微信聊天功能,Android高仿微信聊天界面代码分享
- python如何设置搜狗输入法中英文切换_2020秋季报告:手机输入法AI时代来临,百度输入法优势明显...
- Aaron Swartz:如何提高效率