Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
gpmdf2
Posts : 1
Join date : 2012-09-20

How to read text from an element?  Empty How to read text from an element?

Thu Sep 20, 2012 11:29 pm
Hi, everybody!

I need to read the text from an element. I hav the following:

Code:

  driver = new FirefoxDriver();
  driver.findElement(By.name("myElementID")).getText();

This element HAS text, but the returned text is empty (returns "" ). What is happening? Why I can not get the text?

I can put text inside this element like this:

Code:

  driver.findElement(By.name("myElementID")).sendKeys("someText");

The text is written, works fine. So, why am I having problems when trying to read???
avatar
popsha
Amateur
Amateur
Posts : 60
Join date : 2012-04-14

How to read text from an element?  Empty Re: How to read text from an element?

Mon Sep 24, 2012 9:41 am
Hi,


try like this

System.out.println(driver.findElement(By.name("myElementID")).getText());
avatar
qappbc
Amateur
Amateur
Posts : 38
Join date : 2011-10-13

How to read text from an element?  Empty Re: How to read text from an element?

Mon Oct 29, 2012 4:09 am
are there other identifiers besides 'name' for this element? Like id, class, etc. ?
if yes, then try (using class in example below)

System.out.println(driver.findElements(By.xpath("//*[@class='{whatever the class is}']").getText());
avatar
AnuSrini
Posts : 2
Join date : 2012-10-22

How to read text from an element?  Empty Pls help me in clicking on the links

Tue Oct 30, 2012 11:54 am
How to click on these links?

Can u please let me know? I need to get all the links available in the page and click on all the links. am stuck with clicking on the links.



popsha wrote:Hi,


try like this

System.out.println(driver.findElement(By.name("myElementID")).getText());
avatar
popsha
Amateur
Amateur
Posts : 60
Join date : 2012-04-14

How to read text from an element?  Empty Re: How to read text from an element?

Tue Oct 30, 2012 4:21 pm
Hi AnuSrini,

divide your xpath by rows of a web table. for instance,
xpath = //table[1]/tbody/tr[1]/td[2]/a, here tr[1] is first row number of the wen table.
below is the code for above xpath (web table)

Code:

String xpath_1 = "//table[1]/tbody/tr["
String xpath_2 = "]]/td[2]/a"
try{
int i=1;
while(true){
String val = driver.findElement(By.xpath("xpath_1"+i+"xpath_2")).getText();

i++;
}
} catch(Exception e){}



now you can iterate the "i" to get the link clicked where needed.\

hope this might help you!
avatar
ashish_techie
Amateur
Amateur
Posts : 73
Join date : 2011-08-09

How to read text from an element?  Empty Re: How to read text from an element?

Wed Oct 31, 2012 12:45 am
Is the element hidden?... getText can be used only with visible elements.

Regards
Ashish

For selenium tutorials:
www.qtpselenium.com/selenium-tutorials
Sponsored content

How to read text from an element?  Empty Re: How to read text from an element?

Back to top
Permissions in this forum:
You cannot reply to topics in this forum