Reputation: 718
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 the gettext()
method, but it is returning the ID value.
The content in the 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
WebElement TxtBoxContent = driver.findElement(By.id(WebelementID));
TxtBoxContent.getText();
System.out.println("Printing " + TxtBoxContent);
Printing [[FirefoxDriver: firefox on XP (c0079327-7063-4908-b20a-a606b95830cb)] -> id: ctl00_ContentPlaceHolder1_txtName]
Upvotes: 12
Views: 140760
Reputation: 17553
Python
element.text
Java
element.getText()
C#
element.Text
Ruby
element.text
Upvotes: 0
Reputation: 41
You need to store it in a String
variable first before displaying it like so:
String Txt = TxtBoxContent.getText();
System.out.println(Txt);
Upvotes: 4
Reputation: 9019
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"));
Upvotes: 14
Reputation: 41
text = driver.findElement(By.id('p_id')).getAttribute("innerHTML");
Upvotes: 4