automatictester

my thoughts on test automation

Wait until element contains specified text in Selenium WebDriver

Your goal: wait until element identified by given locator contains expected text.

Assumptions: element may or may not be initially present in DOM, element may or may not have expected text once it’s present in DOM.

Conditions: if element initially is not present, or doesn’t contain expected text, wait up to specified timeout for the condition to be satisfied.

Solution: ExpectedCondition class! Its handy methods should work for you in most cases.

Example:

public boolean isRoadmapLinkDisplayed() {
    return new WebDriverWait(driver, 5).until(ExpectedConditions.
            textToBePresentInElementLocated(ROADMAP_LINK, "Roadmap"));
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: