[英]Wait not working in Firefox browser (Webdriver selenium 2.0 +Java)
我正在使用WebDriver(Eclipse -Java)自动执行注册页面。 单击“注册”按钮后,将显示“成功消息”,并且需要对其进行验证。
我可以在IE8中成功完成此操作。 但是无法在Firefox中进行验证。 我尝试了不同的等待。1. d1.manage()。timeouts()。implicitlyWait(60,TimeUnit.SECONDS);
WebDriverWait等待=新的WebDriverWait(驱动程序,10); wait.withTimeout(30,TimeUnit.SECONDS); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(“ ElmId”)));
等待等待=新FluentWait等待=新FluentWait(d1).withTimeout(60,SECONDS); wait.until(new Function()wait.until(ExpectedConditions.visibilityOf(d1.findElement(By.id(“ elementid”)))));
有没有人遇到过类似的问题? 有什么办法吗?
也许您可以尝试其他条件类型? 或者,您也可以尝试通过覆盖apply方法编写自己的代码。 使用提供的条件还不够的情况很少。 只有在使用我自己的版本的apply方法之后,它才成功。
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(timeoutInSeconds, TimeUnit.SECONDS)
.pollingEvery(pollingInterval,
TimeUnit.MILLISECONDS);
return wait.until(new ExpectedCondition<WebElement>() {
@Override
public WebElement apply(WebDriver arg0) {
List<WebElement> findElements = driver.findElements(By.className(someClassName));
for (WebElement webElement : findElements) {
if (webElement.getText().equals(string)) {
return webElement;
}
}
return null;
}
});
例如,几次这样的事情很有帮助。
单击按钮后,此“成功消息”:它与ajax / javascript一起显示还是您重新加载页面?
如果您使用js进行操作,有时可能无法使用WebDriver命令验证消息,并且您也需要使用js进行验证。 就像是:
Object successMessage = null;
int counter = 0;
while ((successMessage == null) && counter < 5)
{
try
{
((JavascriptExecutor)driver).executeScript("return document.getElementById('yourId')");
}
catch (Exception e)
{
counter +=1;
}
}
if (successMessage != null) //would be better to use some assertion instead of conditional statement
{
//OK
}
else
{
//throw exception
}
while循环是伪等待功能的丑陋方式。 如果不需要等待元素,也可以将其删除。
替代方案可能是
Object result = ((JavascriptExecutor)driver).executeScript("return document.body.innerHtml");
String html = result.toString();
然后手动解析html。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.