Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» FlexMonkium Download Not available under Gorillalogic site
Thu Dec 08, 2016 5:40 pm by bhanu.praveen

» Selenium Script issue
Tue Dec 06, 2016 9:48 pm by njain213

» Difference between QTP, Selenium and Silk test
Tue Dec 06, 2016 7:58 pm by jessicacyrus1

» Where does selenium script pick browser from
Tue Dec 06, 2016 1:52 pm by janbaskt

» Safari throws an HTTP ERROR: 404
Tue Dec 06, 2016 1:51 pm by janbaskt

» Access Denied Error in Selenium RC
Tue Dec 06, 2016 1:51 pm by janbaskt

» Automating Flex application through selenium webdriver
Fri Dec 02, 2016 2:06 pm by abhinay.krs

» Starting with Selenium, what is Selenium?
Mon Nov 28, 2016 4:00 pm by Foma

» Getting started with Selenium
Mon Nov 28, 2016 3:23 pm by Rebbelx

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

How to read text from an element?

View previous topic View next topic Go down

How to read text from an element?

Post by gpmdf2 on 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???

gpmdf2

Posts : 1
Join date : 2012-09-20

Back to top Go down

Re: How to read text from an element?

Post by popsha on Mon Sep 24, 2012 9:41 am

Hi,


try like this

System.out.println(driver.findElement(By.name("myElementID")).getText());

popsha
Amateur
Amateur

Posts : 60
Join date : 2012-04-14

Back to top Go down

Re: How to read text from an element?

Post by qappbc on 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());

qappbc
Amateur
Amateur

Posts : 38
Join date : 2011-10-13

Back to top Go down

Pls help me in clicking on the links

Post by AnuSrini on 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());

AnuSrini

Posts : 2
Join date : 2012-10-22

Back to top Go down

Re: How to read text from an element?

Post by popsha on 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!

popsha
Amateur
Amateur

Posts : 60
Join date : 2012-04-14

Back to top Go down

Re: How to read text from an element?

Post by ashish_techie on 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

ashish_techie
Amateur
Amateur

Posts : 73
Join date : 2011-08-09

Back to top Go down

Re: How to read text from an element?

Post by Sponsored content Today at 3:52 pm


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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