Get the node name for xpath.

1,842 views
Skip to first unread message

Zeebee

unread,
Aug 25, 2015, 8:48:36 AM8/25/15
to robotframework-users

Hi,

Can't find the solution to my issue. I have nodes to be identified, I mean - I have to get nodes names for following case:

<content-scope scope-data="scopeData">
  <link-group data="scopeData[0]">
  <text-img data="scopeData[1]">
</content-scope>

When I'm using following syntax (FirePath, directly from browser)

name((//content-scope[@scope-data='scopeData']/*)[1]) 

or

name((//content-scope[@scope-data='scopeData']/*)[2])

then I get node name ( link-group and text-img).

In robot-framework it doesn't work with keywords Get Text or Get Value. I get message: "InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression name((//content-scope[@scope-data='scopeData']/*)[1]) because of the following error: TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type. (Session info: chrome=44.0.2403.157)"

How to build correct xpath which is interpreted by RF or which keyword should be used?

WarBar

unread,
Aug 26, 2015, 2:12:26 AM8/26/15
to robotframework-users
In s2l when you want use xpath with ( at the begining you need to add prefix
Xpath=( in locator.
Then try again with gat atribut.
Message has been deleted

Zeebee

unread,
Aug 26, 2015, 2:20:18 AM8/26/15
to robotframework-users
Hi, 
@WarBar - I've built variable like that:
${xpath}    xpath=(name((//content-scope[@scope-data='scopeData.cards']/*)[1]))

Now, what keyword should I use to get the first node ([1]) name?

Thanks!

WarBar

unread,
Aug 26, 2015, 4:43:00 AM8/26/15
to robotframework-users
RF code:
Open Browser file:///D:/temp/rf/a.html
${elements} Get Webelements xpath=(//content-scope[@scope-data='scopeData']/*)
log ${elements[0].tag_name}

gives result: 

20150826 10:37:37.551 :  INFO : Creating an instance of the Firefox WebDriver
20150826 10:37:40.326 :  INFO : Opening url 'file:///D:/temp/rf/a.html'
20150826 10:37:40.474 :  INFO : ${elements} = [<selenium.webdriver.remote.webelement.WebElement object at 0x03FCBA10>]
20150826 10:37:40.485 :  INFO : link-group

Hope it helps you

WarBar

unread,
Aug 26, 2015, 4:47:13 AM8/26/15
to robotframework-users
Without prefix "xpath=" and "()" works also correct 
RF code:
Open Browser file:///D:/temp/rf/a.html
${elements} Get Webelements //content-scope[@scope-data='scopeData']/*

Zeebee

unread,
Aug 26, 2015, 4:58:56 AM8/26/15
to robotframework-users
Works great!
Thanks WarBar!

p. s. Dzieki Bartosz :)
Reply all
Reply to author
Forward
0 new messages