【发布时间】:2021-02-02 19:22:25
【问题描述】:
//This command is for scrolling into view of an element
public static void scrollIntoView(WebElement element, WebDriver driver) {
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
}
//This command will make the script wait until a certain element is visible before doing any actions
public static void untilVisibility(WebElement element, WebDriver driver) {
WebDriverWait wait = new WebDriverWait(driver, Helper.TWENTY);
wait.until(ExpectedConditions.visibilityOf(element));
}
//This command will make the script wait until a certain element is clickable before doing any actions
public static void untilClickable(WebElement element, WebDriver driver) {
WebDriverWait wait = new WebDriverWait(driver, Helper.TWENTY);
wait.until(ExpectedConditions.elementToBeClickable(element));
}
我在我的测试用例中使用了这三种方法,但有时脚本仍然无法等待元素的可见性,或者即使在运行时显示了元素,它仍然会失败。但是当我重新运行它们时,它们会单独通过
例如我有 98 个测试用例,第一次运行 20 个会失败,但是当我重新运行 20 个测试用例时,它们通过了
【问题讨论】:
-
您可以尝试在每次测试之前重新加载页面(如果您还没有这样做的话)。您也可以尝试找到存在此问题的较小测试集,这可能会缩小原因。
-
等待是如何配置的?可以分享一下代码吗?