How to find Element By Text in Selenium JUnit?

How to find Element By Text in Selenium JUnit?

Hi Ian!

You will need to add the below code snippet into your test scripts to find Element By Text when conducting Selenium JUnit testing.

 // Locating element with text()
    WebElement e = driver.findElement(By.xpath("//*[text()='5 of 5 remaining']"));
    System.out.println(e.getText());

    // located element with contains()
    WebElement m = driver.findElement(By.xpath("//*[contains(text(),'5 of 5')]"));
    System.out.println(m.getText());

Please check the below GitHub repo for the same.