I am finding a textbox by its ID. I need to get the content which is already there inside the text box. For that I am using gettext() method but it is returning the ID value
Content in text box is: Santhosh
The output I am getting is = [[FirefoxDriver: firefox on XP (c0079327-7063-4908-b20a-a606b95830cb)] -> id: ctl00_ContentPlaceHolder1_txtName]
The code is below
CODE:
WebElement TxtBoxContent = driver.findElement(By.id(WebelementID));
TxtBoxContent.getText();
System.out.println("Printing "+TxtBoxContent);
RESULT:
Printing [[FirefoxDriver: firefox on XP (c0079327-7063-4908-b20a-a606b95830cb)] -> id: ctl00_ContentPlaceHolder1_txtName]
解决方案
You need to print the result of the getText(), you're currently printing the object TxtBoxContent.
getText() will only get the inner text of an element. To get the value, you need to use getAttribute().
WebElement TxtBoxContent = driver.findElement(By.id(WebelementID));
System.out.println("Printing " + TxtBoxContent.getAttribute("value"));