Selenium Java to get the attribute name using relative XPath
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.get("https://kodingwindow.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
What Next?
Selenium Java to locate a web element using the contains() and starts-with() methods
Selenium Java to locate a web element using the text() method
Selenium Java to locate a web element using the last() method
Advertisement