Selenium WebDriver可以结合ExpectedCondition类来定义自己期望的条件 创建一个新的ExpectedCondition接口,必须实现apply方法 等待元素出现 public void testWithImplicitWait(){ System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); WebDriver driver = new ChromeDriver(…
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没有在DOM中找到元素,将继续等待,超出设定时间后,抛出找不到元素异常 即,当元素没有立即出现的时候,隐式等待将等待一段时间后,再查找DOM.默认时间是0. 一旦设置了隐式等待,它将存在在整个webdriver对象实例的生命周期中,隐式等待会让一个正常响应的应用的测试变慢,会在寻找每个元素时进行等待,这样增加了整个测试执行的时间. 应该避免或减少使用隐式等待 //等待60s dri…
对于这一段还蛮有感慨的,只想说,代码还是需要自己去敲的. 1. 改变用户代理 import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.Firefo…
最早接触的selenium是 selenium IDE,当时是为了准备论文.为了用IDE还下载了Firefox浏览器.后来接触过两个项目都需要selenium,一个采用selenium webdirver+junit4 +java,另外一个是采用 robot+selenium2library .总体感觉就是开源.简单.使用范围广.是网页测试必备单品. 关于selenium的好的学习资料: 官方User Guide:  http://seleniumhq.org/docs/ 官方API:  htt…
策略 语法 语法 描述 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测试弹出窗口,包括识别弹出窗口,将driver转到新的窗口,在新的串钩中执行而是步骤,然后再转换到最初的窗口. 通过名称(name)识别和处理: Selenium WebDriver允许我们通过name属性或窗口的句柄来识别窗口,然后通过WebDriver.switchTo().window()方法在不同的窗口之间进行切换. window name属性的定义 name 属性可设置或得到窗口的名称,其值为字符串.语法如下: window.name = [name…
显示等待可以在执行下一次操作时,自定义等待条件 显示的等待只需要执行在需要同步的地方而不影响脚本的其他地方 Selenium WebDriver提供了WebDriverWait和ExpectedCondition类来执行显示等待 ExpectedCondition类提供了一系列预定义好的条件来等待.下面是一些常用的条件 预定义条件 方法名 元素可见可点击 elementToBeClickable(By locator) 元素可被选中 elementToBeSelected(WebElement…
开发环境 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…