Xpath is not recognized as text element but as [object XrayWrapper [object Text]]

3,275 views
Skip to first unread message

Rita Gil

unread,
Sep 24, 2013, 8:19:16 PM9/24/13
to seleniu...@googlegroups.com
Hi

Take a look at the following html:
<div class="box-content">
    <p>
        <b>Delivery Time:</b>
        N/A
    </p>
</div>

I am trying to extract the "N/A" text value so I defined
    xpath = //*div[@class='box-content'][1]//*[contains(text(),'Delivery Time')]/following-sibling::text()[1]
   
When I test this xpath with FirePath it recognizes the N/A text.
But when I run the test that tries to obtain that value through RobotFramework and compare it with another string, I obtain the following error:
    'The given selector //*div[@class=\'box-content\'][1]//*[contains(text(),\'Delivery Time\')]/following-sibling::text()[1] is either invalid or does not result in a WebElement. The following error occurred:\nInvalidSelectorError: The result of the xpath expression "//*div[@class=\'box-content\'][1]//*[contains(text(),\'Delivery Time\')]/following-sibling::text()[1]" is: [object XrayWrapper [object Text]]. It should be an element.
Stacktrace:
    at FirefoxDriver.annotateInvalidSelectorError_ (file:///c:/users/appsca~1/appdata/local/temp/tmp9k18de/webdriver-py-profilecopy/extensions/fxdr...@googlecode.com/components/driver_component.js:8873)
    at FirefoxDriver.prototype.findElementsInternal_ (file:///c:/users/appsca~1/appdata/local/temp/tmp9k18de/webdriver-py-profilecopy/extensions/fxdr...@googlecode.com/components/driver_component.js:8931)
    at fxdriver.Timer.prototype.setTimeout/<.notify (file:///c:/users/appsca~1/appdata/local/temp/tmp9k18de/webdriver-py-profilecopy/extensions/fxdr...@googlecode.com/components/driver_component.js:396) '


I'm using:
- Firefox 23
- And the latest version of RobotFramework and Selenium Webdriver.

I don't know the origin of the problem, but I hope you guys can help.
Thanks

Alexandr Savchuk

unread,
Sep 30, 2013, 10:21:51 AM9/30/13
to seleniu...@googlegroups.com
Hi!

Selenium could not find element wqhich addressed by text node xpath. This is reported in error message.

If you need to get text of element you n3eed to find this element and after that call getText() method.

For your example, i think, you need to find+getText of parent element and remove from it result of find+getTest for all children.


среда, 25 сентября 2013 г., 4:19:16 UTC+4 пользователь Rita Gil написал:
Reply all
Reply to author
Forward
0 new messages