Using gettext method for the specific element using Selenium WebDriver

0 votes

I was fetching a textbox by usinf its ID and fetch the information present in that text box. I was using gettext() method but it is returning the ID value.

The output I am getting is = [[FirefoxDriver: firefox on XP (c0079327-7063-4908-b20a-a606b95830cb)] -> id: ctl00_ContentPlaceHolder1_txtName]

The code is below

Below is my 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]

Apr 10, 2018 in Selenium by xyz
• 1,560 points
28,694 views

1 answer to this question.

0 votes

Mistake is that u r printing the object, not 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"));

answered Apr 10, 2018 by Vardy
• 2,360 points

Related Questions In Selenium

+1 vote
2 answers
0 votes
1 answer

Wait for an element to be accessible using Selenium WebDriver

You can try out the below code: ...READ MORE

answered May 18, 2018 in Selenium by Atul
• 10,240 points
1,744 views
0 votes
2 answers

Is there any way to get the text of a web element using Selenium Webdriver?

use gettext() in java : string lableText = ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
8,459 views
0 votes
1 answer
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,567 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,084 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,178 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,840 views
0 votes
1 answer

Searching for the element with   symbol in selenium

Use Below: //div[@class='Tips' and text()='\u00a0'] READ MORE

answered Apr 20, 2018 in Selenium by Vardy
• 2,360 points
9,275 views
0 votes
1 answer

Reading the pdf file using selenium webdriver

Use should use PDFBox and FontBox. ...READ MORE

answered Apr 25, 2018 in Selenium by Vardy
• 2,360 points
7,820 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP