到目前为止,我使用了2.45.0版本的selenium,所有的等待都是这样完成的:
WebDriverWait wait = new WebDriverWait(webKitUtility.getWebDriver(), 5);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("role")));
Run Code Online (Sandbox Code Playgroud)
但我更新了selenium到3.1.0,我收到错误:
"FluentWait类型中的方法(谓词)不适用于参数(ExpectedCondition)"
我看到从2.45.0到3.1.0,有些东西被弃用了.我正在尝试调查现在最好的方法,但我不确定.我在谷歌上找到的大部分内容都是旧信息,解释方法与我目前使用的方式相同.
请分享有关selenium webdriver的知识.请显示实时示例.
我试图点击该对象,以显示值弹出窗口列表.
我使用了以下脚本,但无法填充列表值弹出窗口.
Driver.findElement(By.xpath(OR.getProperty(Object))).click();
Thread.sleep(1000L);
Run Code Online (Sandbox Code Playgroud)
有没有其他方法可以单击并等待对象?
我有一个单击按钮的方法,但是,当它运行时,selenium会在成功点击时返回结果,而实际上,实际上没有点击按钮.如果我多次运行测试,偶尔会按预期点击它.我将我的测试框架设置为隐式等待大约15秒,我已经设置了明确的等待这个元素,但仍然看到相同的问题.当我这样做时<element>.isDisplayed(),总会找到元素.我将.click放在一个while循环中,点击它几次,大部分时间都有效,但是,有时测试失败了.在单击按钮之前,是否可以使用if语句检查元素是否实际显示?
我试过了:
if(!element.isDisplayed){
element.click
}
Run Code Online (Sandbox Code Playgroud)
这是我遇到问题的按钮:
<button class="notkoButton listNew">
<div class="l6e iconAdd">New List</div>
</button>
Run Code Online (Sandbox Code Playgroud)
这是我的方法:
public marketing_lists_page navigateToNewListPage() throws Throwable {
try {
int x = 0;
while(x < 5) {
newListBtn.click();
x++;
}
//newListPageHeader.isDisplayed();
} catch (NoSuchElementException e){
logs.errorDetails("Could not navigate to New List Page");
Assert.fail();
}
return this;
}
Run Code Online (Sandbox Code Playgroud) 如果我的问题听起来很重要,我会提前道歉,我在QA和Selenium都很新.
我使用Java和Selenium编写测试,有时我需要等待Web元素可访问,下面是我以前使用的代码片段:
int counter = 0;
while (true) {
counter++;
boolean breakIt = false;
try {
WebElement element= driverChrome.findElement(By.xpath("bla bla"));
element.click();
breakIt = true;
} catch (Exception e) {
Thread.sleep(1000);
}
if (breakIt) {
break;
}
if (counter > 4) {
System.out.println("Failed");
tearDown();
System.exit(1);
}
}
Run Code Online (Sandbox Code Playgroud)
但现在在某处我看到了这个:
WebDriverWait wait = new WebDriverWait(driverChrome, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("bla bla"))).click();
Run Code Online (Sandbox Code Playgroud)
肯定第二个更短但我不知道它是否更好,换句话说,它们是不同的吗?如果是,怎么样?哪一个更好用于哪些目的?