3

Please help me find the xpath for the page https://www.seleniumhq.org/download/

In this page there is a para "Selenium Standalone Server". In that I have to find the xpath for Download version link "3.141.59". Since it is a number I cannot use this number to find as it's dynamic and it may change in near future. Please help me with this.

enter image description here

  • 1
    Welcome: have a look at how to ask. You might get downvotes for not trying yourself first. What did you research, what did you try? It looks like a homework question... – Ray Oei Dec 16 '18 at 14:19
  • Have you tried inspecting the DOM? – Mike Warren Dec 16 '18 at 18:03
1

You need to use the surrounding context which (presumably) will not change and search for the link within that context regardless of the contents of the link.

One way of doing that:

//h3[text()='Selenium Standalone Server']/following-sibling::p[contains(text(),'Download version')][1]/a

Explanation of the above xpath:

We want the link within the Selenium Standalone Server section:

//h3[text()='Selenium Standalone Server']

We see the paragraph we are looking for is on the same level as the h3 title, so we use the following-sibling axis:

 //h3[text()='Selenium Standalone Server']/following-sibling::p

This returns many elements, we only want the one with our link which we identify by the Download version text:

//h3[text()='Selenium Standalone Server']/following-sibling::p[contains(text(),'Download version')]

We are only interested in the first one:

//h3[text()='Selenium Standalone Server']/following-sibling::p[contains(text(),'Download version')][1]

And we are looking for the link within that paragraph, which is our final xpath:

//h3[text()='Selenium Standalone Server']/following-sibling::p[contains(text(),'Download version')][1]/a

Hope this helps!

1

This xPath should work perfectly:

//p[normalize-space(text())="Download version"]/a

Basically, it can be simplified to

//p[text()="Download version "]/a

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.