[英]Pause/continue Execution of selenium script in webdriver
我的項目工作量很大。 如果在包含100個步驟的第99步中出現任何錯誤,我將使用selenium自動執行這些流程,然后我需要從第一步開始。
因此,即使沒有找到定位符,也有任何東西可以暫停/繼續硒腳本。
public void waitForElementToBeVisible(String cssSelector) throws Throwable {
try {
WebDriverWait wait = new WebDriverWait(driver, 30); //30 = TIMEOUT DURATION IN SECONDS
wait.until(ExpectedConditions.or(
ExpectedConditions.visibilityOfElementLocated(By.cssSelector(cssSelector)) //CSS SELECTOR CAN BE DEFINED WHEN THIS METHOD IS CALLED e.g. waitForElementToBeVisible("Button");
));
} catch (Exception e) {
System.out.println("Timeout exceeded");
//ACTIONS YOU WANT TO CARRY OUT IF THE ELEMENT CAN'T BE FOUND, COULD JUST BE NOTHING.
}
}
或者,如果您想在測試中運行此程序,而無需設置方法,只需執行以下操作即可。...
try {
WebDriverWait wait = new WebDriverWait(driver, 30); //30 = TIMEOUT DURATION IN SECONDS
wait.until(ExpectedConditions.or(
ExpectedConditions.visibilityOfElementLocated(By.cssSelector("Button")) //CSS SELECTOR CAN BE DEFINED WHEN THIS METHOD IS CALLED e.g. waitForElementToBeVisible("Button");
));
} catch (Exception e) {
System.out.println("Timeout exceeded");
//ACTIONS YOU WANT TO CARRY OUT IF THE ELEMENT CAN'T BE FOUND, COULD JUST BE NOTHING.
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.