简体   繁体   中英

Pause/continue Execution of selenium script in webdriver

I have a large flows in my project. I am automating these flows using selenium if I get an any error in 99th step consisting of 100 steps then I need to start from first step.

So is there any thing to pause/continue selenium script even though if locator not found.

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.
    }
}

alternatively, if you want to run this within your test, without setting up a method, simply do the following....

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.
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM