【发布时间】:2014-02-28 15:24:59
【问题描述】:
在我的时区下午好。
我开始使用 Selenium 来测试我的 Web 应用程序。我正在使用带有 IEDriverServer.exe 的 WebDriver API。操作系统 -> Windows XP 主要问题是测试不稳定。有时它们运行,有时它们抛出异常。 例如,这是测试不稳定的常见地方。 我必须打开一个新窗口并开始填写一些字段。
driver.findElement(By.xpath("//input[@name='"+button+"' and @type='button']")).click();//BUTTON THAT OPENS THE NEW WINDOW
long initDate = System.currentTimeMillis();
while(driver.getWindowHandles().size() <= numberPopUps){
Thread.sleep(500);
//15 seconds waiting for the pop-up
if((System.currentTimeMillis() - initDate) > 15000){
throw new Exception("Timeout to open popup");
}
}
for(String winHandle : driver.getWindowHandles()){
if(!winHandle.equals(mWindow)){
driver.switchTo().window(winHandle);
break;
}
}
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);//WAIT THAT THE PAGE COMPLETELY LOAD
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@name='descricaoMov']")));//VERIFY IF THIS INPUT IS ON THE DOM
`driver.findElement(By.xpath("//input[@name='descricaoMov']")).sendKeys("TESTE SELENIUM");`//This is where sometimes the test throws exception saying that is unable to find this element
,我想问这怎么可能?
提前致谢 最好的问候
【问题讨论】:
-
我想到了一些事情。您的 while 循环只是从
WebDriverWait/FluentWait复制代码 - 它是为在这种情况下“等待”而设计的。其次,什么版本的IE?三是什么版本的IE驱动?另外,您遇到了什么错误?每次都是一样的吗?如果没有,是什么?它多久失败一次?每2次运行?每 10 次运行?最后,您是否正确设置了保护模式设置? -
Ie 版本 8 IE DRiver 版本 2.39 发生错误时总是相同的“未找到 WebElement 'input[@name='descricaoMov''” 我没有配置任何保护模式设置,因为在IEDriver 页面规范没有说明任何与 Windows XP 相关的内容,只针对高级版本
标签: java selenium xpath selenium-webdriver