Axl*_*Axl 1 java selenium selenium-webdriver
我有一个 Selenium WebDriver 测试,它在关闭模式窗口然后等待元素后失败。具体来说,它无法在FluentWait调用中查找元素。我尝试了各种不同的设置等待的方法,但都没有奏效。这是我认为应该起作用的:
失败的测试代码:
driver.findElement(By.className("dismiss")).click(); // this dismisses a modal window
driver.switchTo().defaultContent();
FluentWait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver)
.withTimeout(30, TimeUnit.SECONDS)
.pollingEvery(500, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class);
fluentWait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.className("next"))));
driver.findElement(By.className("next")).click();
Run Code Online (Sandbox Code Playgroud)
这里失败发生在等待调用中寻找元素:
org.openqa.selenium.NoSuchElementException:无法定位元素:{"method":"class name","selector":"next"} 命令持续时间或超时:1.33 秒有关此错误的文档,请访问:http:// /seleniumhq.org/exceptions/no_such_element.html构建信息:版本:'2.41.0',修订:'3192d8a',时间:'2014-03-27 17:17:32' 系统信息:主机:'7rzrgv1.bsolver.local',IP:'10.0.3.103 ', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-431.el6.x86_64', java.version: '1.7.0_60' Session ID: 56c5a752-68fd- 4cdb-ae57-2fcefc930f6f 驱动程序信息:org.openqa.selenium.firefox.FirefoxDriver Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, browserConnectionEnabled true,webStorageEnabled=true,nativeEvents=false,rotatable=false,locationContextEnabled=true,applicationCacheEnabled=true,takesScreenshot=true,version=24.6.0}]
如果我fluentWait.until用 a替换呼叫Thread.sleep(5000),则click()每次都有效。
一个有趣的注意事项……这只发生在在 Xvfb 上运行 Firefox 的无头机器上运行测试时。当存在实际的 GUI 时不会发生这种情况。
所以,有几个问题:
为什么FluentWait不忽略NoSuchElementException?
除了隐式等待之外,有没有人想过一种更优雅的方式来处理这个问题?
我有同样的问题。@Karna 和 @Axl 帮我弄清楚了。我正在使用import java.util.NoSuchElementException;而不是import org.openqa.selenium.NoSuchElementException;.
| 归档时间: |
|
| 查看次数: |
1201 次 |
| 最近记录: |