Selenium WebDriver没有实现Selenium RC的isElementPresent()方法来检查页面上的元素是否存在. 在WebDriver中封装一个类似的方法,如下: public boolean isElementPresent(WebDriver driver, By by){ try{ driver.findElement(by); return ture; }catch(Exception e){ return false; } }…
许多测试失败是因为点击一个元素失败或者在一个不可见的字段中输入文字,或者是在不可输入的文本中输入文字. 我们可以在具体操作之前,检查一下元素的状态.WebElement类提供了这样的方法. 方法 目的 isEnabled() 检查元素是否启用(只有在input元素设为disabled时,返回false) isSelected() 检查元素是否被选中(单选.多选.下拉框) isDisplayed() 检查元素是否可见…
1.简单查找 By ID: WebElement element=driver.findElement(By.id("userId")); By Name:WebElement element=driver.findElement(By.name("cheese")); By TagName:WebElement element=driver.findElement(By.tagName("a")); By ClassName:WebElemen…
Selenium Webdriver 学习: http://jarvi.iteye.com/category/203994 https://github.com/easonhan007/webdriver_guide Selenium WebDriver经验杂记:http://blog.csdn.net/ant_yan/article/details/8185899http://blog.csdn.net/aerchi/article/category/936247 1. Selenium We…
1. 获取元素文本 WebElement类的getText()方法返回元素的innerText属性.所以元素里如果有子节点一样也会被返回出来.如下所示 public class GetText { @Test public void testGetText(){ //启动driver,打开被测页面 System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); WebDriver driver =…
Selenium webdriver 学习总结-元素定位 webdriver提供了丰富的API,有多种定位策略:id,name,css选择器,xpath等,其中css选择器定位元素效率相比xpath要高些,使用id,name属性定位元素是最可靠,效率最高的一种办法. 1.工具选择:在我们开发测试脚本的过程中各个浏览器给我们也提供了方便定位元素的工具,我比较喜欢使用firefox的firebug工具,也是目前很多开发测试人员比较热衷的选择,原因是firefox是唯一能够集成selenium IDE…
策略 语法 语法 描述 By id driver.findElement(By.id()) driver.findElements(By.id()) 通过id属性定位元素 By name driver.findElement(By.name()) driver.findElements(By.name()) 通过name属性定位元素 By class name driver.findElement(By.className()) driver.findElements(By.className(…
Selenium WebDriver可以结合ExpectedCondition类来定义自己期望的条件 创建一个新的ExpectedCondition接口,必须实现apply方法 等待元素出现 public void testWithImplicitWait(){ System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); WebDriver driver = new ChromeDriver(…
Selenium WebDriver提供了隐式等待来同步测试.当使用了隐式等待执行测试的时候,如果WebDriver没有在DOM中找到元素,将继续等待,超出设定时间后,抛出找不到元素异常 即,当元素没有立即出现的时候,隐式等待将等待一段时间后,再查找DOM.默认时间是0. 一旦设置了隐式等待,它将存在在整个webdriver对象实例的生命周期中,隐式等待会让一个正常响应的应用的测试变慢,会在寻找每个元素时进行等待,这样增加了整个测试执行的时间. 应该避免或减少使用隐式等待 //等待60s dri…
开发环境 JDK 下载地址: http://www.oracle.com/technetwork/java/javase/downloads/index.html Eclipse: 下载地址:http://www.eclipse.org/downloads/ Selenium jar包 (这里用的是:selenium-java-2.45.0.zip ,selenium-server-standalone-2.45.0.jar) 下载地址:http://code.google.com/p/sele…