Selenium Java script to locate web element by XPath using contains() and starts-with() methods
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) { WebDriver driver; System.setProperty("webdriver.chrome.driver", "/home/kodingwindow/drivers/chromedriver"); driver = new ChromeDriver(); driver.manage().window().maximize(); 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("//*[starts-with(@name,'log')]")).click(); driver.close(); } }
Comments and Reactions
What Next?
Selenium Java to locate a web element using the text() method
Selenium Java to locate a web element using the last() method
Selenium Java to locate a web element using the following and preceding XPath axes
Advertisement