Selenium Java to get the attribute name using relative XPath
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) { System.setProperty("webdriver.chrome.driver", "/home/codeaft/drivers/chromedriver"); WebDriver driver = new ChromeDriver(); driver.get("https://codeaft.github.io/testapp/"); System.out.println(driver.findElement(By.xpath("//input[@type='text']")).getAttribute("id")); System.out.println(driver.findElement(By.xpath("//input[@type='text']")).getAttribute("maxlength")); System.out.println(driver.findElement(By.xpath("//input[@type='password']")).getAttribute("name")); driver.close(); } }
Output
username 15 password
Comments and Reactions