3.1定位

<button id="gbqfba" aria-label="Google Search" name="btnK" class="gbqfba"><span id="gbqfsa">Google Search</span></button>

3.1.1 By.name("xxx")-定位name属性

driver.findElement(By.name("btnK")).click();

3.1.2 By.id()--按id定位

3.1.3 By.linkText()--定位超链接

<a href="/intl/en/about.html">About Google</a>
driver.findElement(By.linkText("About Google")); //匹配部分文字
driver.findElement(By.partialLinkText("About"));

3.1.4 By.cssSelector()--速度快

3.1.5 By.xPath()--速度慢-终极方法

//F12控制台-->Element-->找到元素-->右键copy-->copy Xpath即可
dr.findElement(By.xpath("/html/body/div[2]/div/div/div[1]/a[2]")).click();

3.2 元素操作

3.2.1 输入框

WebElement element = driver.findElement(By.id("passwd-id"));
//将输入框清空
element.clear();
//在输入框中输入内容:
element.sendKeys(“test”);
//获取输入框的文本内容:
element.getText();

3.2.2 下拉框-Select

Select select = new Select(driver.findElement(By.id("select")));
select.selectByVisibleText(“A”);
select.selectByValue(“1”);
select.deselectAll();
select.deselectByValue(“1”);
select.deselectByVisibleText(“A”);
select.getAllSelectedOptions();
select.getFirstSelectedOption();

3.2.3 多选框

WebElement checkbox = driver.findElement(By.class(".checkbox"));
checkbox.click();
checkbox.clear();
checkbox.isSelected();
checkbox.isEnabled();

3.2.4 按钮

WebElement btn= driver.findElement(By.id("save"));
btn.click();      //点击按钮
btn.isEnabled ();  //判断按钮是否enable

3.2.5 弹出框

Alert alert = driver.switchTo().alert();
//确定
alert.accept();
alert.dismiss(); //取消
alert.getText();//获取文本

最新文章

  1. DA - 信息获取途径汇总
  2. gcc参数-l传递顺序错误导致`undefined reference&#39;的一点小结
  3. CentOS 配置网络yum源
  4. mediawiki的安装与配置
  5. nn_slow和nn_fast
  6. animation of android (2)
  7. 小扩展大用处,自己扩展一个ForeachRead吧
  8. 【Unity Shaders】初探Surface Shader背后的机制
  9. iOS开发技巧系列---详解KVC(我告诉你KVC的一切)
  10. hdu1002大数相加
  11. 多线程、Socket
  12. 20170714_js闭包变量重置
  13. bzoj 3597: [Scoi2014]方伯伯运椰子
  14. dede后台出现   保存目录数据时失败,请检查你的输入资料是否存在问题
  15. 如何在同一台机器上安装多个MySQL的实例
  16. ios屏幕怎么投屏到电脑显示器
  17. TensorFlow中的通信机制——Rendezvous(二)gRPC传输
  18. MongoDB数据库简单操作
  19. Python:每日一题003
  20. 4.5Python数据类型(5)之列表类型

热门文章

  1. spring扩展点之二:spring中关于bean初始化、销毁等使用汇总,ApplicationContextAware将ApplicationContext注入
  2. PCB设计基础及技巧
  3. C语言学习笔记--C语言中的逗号表达式
  4. nodejs PK php全方位比较PHP的Node.js的优缺点
  5. mongodb操作数据集合
  6. datanode与namenode的通信原理
  7. 5、预测和鉴定miRNA的靶基因
  8. asp.net刷新本页面的六种方法总结
  9. Linux 最小系统挂载U盘(SD、TF卡)并执行程序
  10. python 里 np.array 的shape (2,)与(2,1)的分别是什么意思,区别是什么?