Skip to content

Instantly share code, notes, and snippets.

@qagoose
Created April 15, 2018 14:40
Embed
What would you like to do?
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class BadExample {
private WebDriver driver;
public BadExample(WebDriver driver) {
this.driver = driver;
}
public String clickElementAndGetText(String elementToClickId, String elementToReadId) {
// Click the element we want to click
driver.findElement(By.id(elementToClickId)).click();
// Wait until the element we want to get the text from is visible
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(elementToReadId)));
// Get the text from our read element and return it
return driver.findElement(By.id(elementToReadId)).getText();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment