在java selenium中单击某个元素之前,如何等待该元素被启用?
大家好,我对selenium很陌生,我想知道最好是等待一个元素被启用。我正在编写一个测试来下载一份报告,该报告要求在出现下载按钮之前,将表中的状态设置为“完成”。我曾尝试使用isDisplayed()函数,但到目前为止它失败了。我还需要定时器是动态的,以不断检查,直到报告下载前完成
public static boolean isElementVisible(WebElement element) throws Exception {
return element.isDisplayed();
}
public void statusCheck() throws Exception {
if(Utils.isElementVisible(status)){
downloadButton.click();
}
else{
wait(100000);
}
}
# 1 楼答案
你可以改用WaitDriver
https://www.selenium.dev/documentation/en/webdriver/waits/ https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#or-org.openqa.selenium.support.ui.ExpectedCondition
# 2 楼答案
关于元素的更多信息,如果
wait for an element
和status to be set at "Complete"
指的是同一个元素或不同的元素,则有助于我们构建标准答案如果它们都引用相同的WebElement,而不是使用^{} 进行验证,则需要为^{} 引入WebDriverWait,并且可以使用以下Locator Strategy:
注意:对于webelements,没有像
isElementVisible()
这样的方法如果它们都引用不同的WebElements,那么可以使用} 和Locator Strategy归纳WebDriverWait,并且可以使用以下Locator Strategy:
and
子句为^{