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
Advertisement