Selenium Java script to locate web element by XPath using contains() and starts-with() methods
Codeaft.java
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; class Codeaft { public static void main(String[] args) { WebDriver driver; System.setProperty("webdriver.chrome.driver", "/home/codeaft/drivers/chromedriver"); driver = new ChromeDriver(); driver.manage().window().maximize(); driver.navigate().to("https://codeaft.github.io/testapp/"); driver.findElement(By.xpath("//*[contains(@name,'ername')]")).sendKeys("codeaft"); driver.findElement(By.xpath("//*[contains(@name,'passw')]")).sendKeys("codeaft"); driver.findElement(By.xpath("//*[starts-with(@name,'log')]")).click(); driver.close(); } }
Comments and Reactions