trying to click on link with xpath starting with html/body - how to work out xpath?

1,128 views
Skip to first unread message

jloyzaga

unread,
Jun 17, 2016, 1:21:25 AM6/17/16
to robotframework-users
xpath from firebug(firepath)

html/body/div[1]/div[3]/div[1]/div/div[3]/div[1]/div[1]/div/div/div[2]/div[6]/div/div[2]/div/div/div/ul/em/li[1]/a/strong

the item I want to action is in red

<div class="content">
<p style="text-align: center;">
<p>Welcome to Environmental Data Portal Map View.</p>
<p>
<ul class="list-menu has-icon bound-visible">
<em>
<li class="list-menu-item">
<a class="list-menu-details" style="text-decoration: none !important; color: black; margin-left:0em;" href="http://dev.edptest.info/">
<img class="list-menu-icon bound-visible-inline" style="padding:5px;" src="Resources/Images/Icons/Toolbar/home-24.png" alt=" "/>
<strong class="list-menu-name">  Open Portal Home page</strong>
<span class="list-menu-desc bound-visible">Click to navigate to EDP Portal hompage.</span>
</a>
</li>
<li class="list-menu-item" style="margin-left:0em;">
</em>
</ul>
<em/>
<p/>
</div>

J Wipf

unread,
Jun 17, 2016, 6:20:10 AM6/17/16
to robotframework-users
If you read the documentation on Click Link [1] you will notice that it accepts link text. That would be the easiest solution. In your case this should be '  Open Portal Home page'.

Kevin O.

unread,
Jun 17, 2016, 12:23:23 PM6/17/16
to robotframework-users
First, I must say that using an XPath like that is strongly discouraged. This is because it is very fragile. Slight changes to the DOM will break your test.
The suggestion to use link text is good. Unless you need to test localized versions of this web app, then you should look for alternatives.

You did not mention what you had tried. So I'm going to guess what the issue might be.
If you want to start from the root of the document (html), the xpath you posted is fine.
But in order to use it, you need to specify the locator type explicitly.

Click Element    xpath=html/body/div[1]/div[3]/div[1]/div/div[3]/div[1]/div[1]/div/div/div[2]/div[6]/div/div[2]/div/div/div/ul/em/li[1]/a/strong

Click element is used here because you are trying to click on a strong element. Click Link filters elements and will only work on a (anchor) elements.
Perhaps that is your issue.

This will probably work:
Click Link    xpath=html/body/div[1]/div[3]/div[1]/div/div[3]/div[1]/div[1]/div/div/div[2]/div[6]/div/div[2]/div/div/div/ul/em/li[1]/a

The reason you must specify xpath= is because your xpath does not start with //.
Here's some other XPaths that would also need the locator prefix:
(//a)[5]
id('someTable')/th/td[2]


On Friday, June 17, 2016 at 12:21:25 AM UTC-5, jloyzaga wrote:

jloyzaga

unread,
Jun 19, 2016, 9:32:10 PM6/19/16
to robotframework-users
the link cannot be found

Prashant

unread,
Jun 21, 2016, 4:00:03 PM6/21/16
to robotframe...@googlegroups.com
Try This 

Click Element  css= .list-menu-details>img>span  

dm08

unread,
Jun 21, 2016, 4:02:20 PM6/21/16
to bharambep...@gmail.com, robotframework-users
Hi 

“//“  will cause invalid selector error. Probably you mean "css=.list-menu-details>img>span" ?

Thanks,
Dmitriy

On Jun 21, 2016, at 1:00 PM, Prashant <bharambep...@gmail.com> wrote:

 css= //list-menu-details>img>span 

dm08

unread,
Jun 21, 2016, 4:37:53 PM6/21/16
to bharambep...@gmail.com, robotframework-users
I see that it is the invalid selector. It is  mixed up css selector with xpath.

css=.list-menu-details>img>span  
or 
xpath=//*[@class='list-menu-details’]/img/span 

More about css selectors http://www.w3schools.com/cssref/css_selectors.asp as you can see “/“ is not here 

InvalidSelectorException: Message: The given selector //* is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: An invalid or illegal selector was specified
Stacktrace:



On Jun 21, 2016, at 1:28 PM, Prashant Bharambe <bharambep...@gmail.com> wrote:

Did u try?
Reply all
Reply to author
Forward
0 new messages