Can't get the span text from Robot

2,245 views
Skip to first unread message

Huizhen WU

unread,
Aug 7, 2014, 12:03:59 PM8/7/14
to robotframe...@googlegroups.com
Hello all,

I'm trying to get text value from a <span>tag: code html :

<div id="homeGrid1headerListSearch" class="rapportNav roundCorner_ieless">
<div class="nbResult">
<span class="number">41</span>
Report(s)
</div>

I tried a lot of methods to locate the position of it like 
element text should be //div[@id='homeGrid1headerListSearch']/div/span[@class='number'] ${report_requested_number}

element text should be css=span.number                                                                                 ${report_requested_number}
element text should be //div[@id='homeGrid1headerListSearch']/div/span                                ${report_requested_number}

and it will be returned the same error :

connection                                                                                                                 | FAIL |
ValueError: Element locator 'css=span.number' did not match any elements.



Can some guys have an ideal about it?


Thanks : )


Tatu Aalto

unread,
Aug 8, 2014, 3:34:38 AM8/8/14
to Huizhen WU, robotframework-users

Ugh

Firebug [1] and firepath [2] are the best tools to solve issues like this.

-Tatu
Send from my mobile

[1] http://getfirebug.com
[2] https://getfirebug.com/wiki/index.php/Firebug_Extensions#FirePath

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Huizhen WU

unread,
Aug 8, 2014, 5:30:56 AM8/8/14
to robotframe...@googlegroups.com, huizhen...@gmail.com
hello !!

Thanks for your solution.
I have already installed firebug, and I just add on firepath , I copied the xpath in to robot., it returned same error,,,,

connection                                                                                                                 | FAIL |
ValueError: Element locator '//*[@id='homeGrid1headerListSearch']/div[1]/span' did not match any elements.

and if I delete * like 
connection                                                                                                                 | FAIL |
ValueError: Element locator '//[@id='homeGrid1headerListSearch']/div[1]/span' did not match any elements.

it return error for :

InvalidSelectorException: Message: u'The given selector //[@id=\'homeGrid1headerListSearch\']/div[1]/span is either invalid or does not result in a WebElement. The following error occurred:\nInvalidSelectorError: Unable to locate an element with the xpath expression //[@id=\'homeGrid1headerListSearch\']/div[1]/span because of the following error:\n[Exception... "The expression is not a legal expression."  code: "12" nsresult: "0x805b0033 (SyntaxError)"  location: "<unknown>"]' ; Stacktrace: 


I'm lost.....


To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.

Tatu Aalto

unread,
Aug 8, 2014, 5:40:14 AM8/8/14
to huizhen...@gmail.com, robotframe...@googlegroups.com

Ugh

Then most likely the element is not yet there when the keyword gets executed. I usually do first:
Wait Until Page Contains Element keyword before I do any other actions on the desired DOM tree section. This is because I want to make sure that all required elements are present before I interact with them. And I try to choose the element to be the last element to be loaded on the page/DOM tree section.

-Tatu
Send from my mobile

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

NIKHIL RAJGARHIA

unread,
Aug 17, 2017, 9:58:26 AM8/17/17
to robotframework-users
I know its already 4 years of this post. Since I saw an error would post it.
If the elements are arranged in the same way as you have mentioned..then your xpath is wrong. I think only 'span[@class='number']' should work. Since, 'span' is not the child element of 'div' it's a sibling. I hope it helps.

Thanks,
Nikhil kumar
Reply all
Reply to author
Forward
0 new messages