Selenium: how to getText() with Selenium WebDriver

Last updated on:

From time to time you want make sure that text on the page was not changed by any chance, here is how you would do that:


WebElement textLocation = driver.findElement(By.id("importantText"));
assertEquals(textLocation.getText(), "Here is some important text");

In recent versions of WebDriver engineers experienced problems using getText() with title, if you have same problem you might use getAttribute(“text”).

View Comments

Leave a Comment

Use markdown or basic HTML and be nice.