Selenium Java to get the attribute name using relative XPath
GD.java
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; class GD { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "/home/godarda/drivers/chromedriver"); WebDriver driver = new ChromeDriver(); driver.get("https://godarda.com/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