Harshal Bagul Harshal Bagul - 7 months ago 10
Java Question

Unable to get Text in Textbox using getText() or getAttribute()

.

My code is:

Using getText();
WebElement TxtBoxContent = driver.findElement(By.id("FIRST_NAME"));
System.out.println("Printing " + TxtBoxContent.getText());


For attribute, value attribute not present.
so what i do right now?
Please give me perfect solution??

Answer

hi please note that when you want to print value inside the text box then in general in source code you will not find any attribute holding text box value cause its value lies inside a hidden attribute know as value so please try like below it will print correct value

WebElement TxtBoxContent = driver.findElement(By.id("FIRST_NAME"));
System.out.println("Printing " + TxtBoxContent.getAttribute("value"));

hope this helps you