Selenium Java to locate web element by XPath using text() method
KW.java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

class KW 
{
    public static void main(String[] args) 
    {
        System.setProperty("webdriver.chrome.driver", "/home/kodingwindow/drivers/chromedriver");
        WebDriver driver = new ChromeDriver();
        driver.navigate().to("https://kodingwindow.com/testapp/");
        
        driver.findElement(By.xpath("//*[contains(@name,'ername')]")).sendKeys("kodingwindow");
        driver.findElement(By.xpath("//*[contains(@name,'passw')]")).sendKeys("kodingwindow");
        driver.findElement(By.xpath("//*[text()='Reset']")).click();
        driver.close();
    }
}
Advertisement