Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
277 views
in Selenium by
retagged by
I have an application where I have to wait until element is visible. How do I achive this?

1 Answer

0 like 0 dislike
by
 
Best answer
/**
     * Function to explicitly wait for an element to become visible for a
     * designated duration
     * 
     * @param driver
     *            -WebDriver currently in use by script
     * @param by
     *            -By identifying the element to be interacted with
     * @param duration
     *            -Int identifying the wait time in seconds
     */
    protected static void waitForVisible(WebDriver driver, By by, int duration, String selector) {
        for (int x = 0; x <= 5; x++) {
            try {
                new WebDriverWait(driver, duration).until(ExpectedConditions.visibilityOfElementLocated(by));
                break;
            } catch (StaleElementReferenceException e) {
                e.printStackTrace();
            }
        }
    }


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...