power_settings_new

how do i wait for element to be visible

by
asked
0 votes
119 views
I have an application where I have to wait until element is visible. How do I achive this?

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

answered by
0 votes
 
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();
            }
        }
    }

Related questions

1
keyboard_arrow_down
add
...