Webdriver: getText() returning empty string

已查看 5,525 次
跳至第一个未读帖子

Smita Sinha

未读,
2012年7月24日 04:43:122012/7/24
收件人 seleniu...@googlegroups.com
Hi All,

My HTML code is:
<span id="A0948:iceform:j_idt247" class="iceOutTxt  alert">Error text</span>

I want to get the text "Error text"

My code:
WebElement webEl = driver.findElement(By.xpath("//span[@id = 'A0948:iceform:j_idt247']"));
System.out.println("Get Text:"+webEl.getText());

The output is null
Get Text:

Someone please help me in resolving this.

Thanks,
Smita

Peter Gale

未读,
2012年7月24日 04:59:382012/7/24
收件人 Selenium Users
What happens if you try to get the class attribute of this element?


Date: Tue, 24 Jul 2012 14:13:12 +0530
Subject: [selenium-users] Webdriver: getText() returning empty string
From: sayhi....@gmail.com
To: seleniu...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Smita Sinha

未读,
2012年7月24日 05:11:592012/7/24
收件人 seleniu...@googlegroups.com
Hi Peter,
I am getting the class attribute.

O/P
Class: iceOutTxt  alert

Code:
WebElement webEl = driver.findElement(By.xpath("//span[@id = 'A0948:iceform:j_idt247']"));
System.out.println("Class:"+ webEl.getAttribute("class") );

Thanks,
Smita

Smita Sinha

未读,
2012年7月24日 05:13:312012/7/24
收件人 seleniu...@googlegroups.com
I even tried this.
 text = (String) ((JavascriptExecutor)driver).executeScript("document.getElementById(\"A0948:iceform:j_idt247\").innerText");
 System.out.println("Text Inside:"+text);

O/P
Text Inside:null

Don`t know whats wrong.

Thanks,
Smita

Mark Collin

未读,
2012年7月24日 05:21:522012/7/24
收件人 seleniu...@googlegroups.com

Are there two elements on the page with the same ID (A bug if there are)?  If so you could be pulling the text from the wrong one.

Smita Sinha

未读,
2012年7月24日 05:24:512012/7/24
收件人 seleniu...@googlegroups.com
No Mark,
There is only one element on the page with this id (Using firefinder) and 
webEl.isEnabled() returns true.


-Smita

Peter Gale

未读,
2012年7月24日 05:27:192012/7/24
收件人 Selenium Users
Does the same type of code work on other SPAN elements?

I'm not sure to what extent span tags are different to other tags and only affect part of the text in the parent, i.e. they can contain no text themselves.

Try to get the text of the parent object:

WebElement webEl = driver.findElement(By.xpath("//span[@id = 'A0948:iceform:j_idt247']/.."));
System.out.println("Get Text:"+webEl.getText());


Date: Tue, 24 Jul 2012 14:43:31 +0530
Subject: Re: [selenium-users] Webdriver: getText() returning empty string

Smita Sinha

未读,
2012年7月24日 06:02:412012/7/24
收件人 seleniu...@googlegroups.com
Thankyou Mark and Peter,

Clicking on the element before getText() has resolved this issue.

-Smita

madeja madeja

未读,
2015年10月1日 10:20:572015/10/1
收件人 Selenium Users
Hi, this click totaly help me... thanks

Dňa utorok, 24. júla 2012 12:02:41 UTC+2 sayhi_...@yahoo.com napísal(-a):

Ripon Al Wasim

未读,
2015年10月2日 01:47:092015/10/2
收件人 seleniu...@googlegroups.com
Hi,
Can you please provide the HTML code snippet for this?

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.
回复全部
回复作者
转发
0 个新帖子