1

Looking for an XPath for a webpage where after every booking a Rel# generate. Need to validate the Rel# is saved in a different tab or not.

So the HTML page says:

Rel#:

I tried with the given xpath

"//*[@id="summaryDiv"]/table[4]/tbody/tr[2]/td[1]/b[2]"

also with "//b[contains(.,'Rel#:')]/parent::td"

But every time it returns the value "b" but not any relation numbers.

What should I use identifying the correct XPath for Rel#?

  • To make it easier to copy and paste for testing, it would be nice if the relevant html was posted directly in the question. This also helps for people who work on networks that block image sharing sites, or if the link ever goes dead. Otherwise, this is a great question. Cheers :) – mrfreester Jul 28 '17 at 16:20
  • 3
    Possible duplicate of How to handle dynamic changing ID's In XPath? – Bharat Mane Jul 28 '17 at 18:05
  • @BharatMane I think this is a different enough situation from that duplicate suggestion as the XPath nodes aren't dynamic in this case, rather the value trying to be retrieved is. This is more of a case trying to distinguish between br and text() nodes that don't have clear attributes. – mrfreester Jul 31 '17 at 14:45
1

Step one would be to tell development to make the html more automation friendly, because this is pretty awful. :) I hope you have good persuasion skills.

You can probably clean this up, but here is an example using both contains and text()= for getting the text element.

"//*[@id='summaryDiv']/table[4]//text()[following-sibling::b[contains(text(), 'Unit Numb')] and preceding-sibling::b[text()='Rel#:']]"

The important thing to remember here, is that even though you don't see a tag around some of the text, text() itself can work to find those text() elements, as if it was a normal tag.

While following and preceding may look a bit backwards here, it essentially means look for some text before the 'b' node text that contains 'Unit Numb' and after the 'b' node text that is 'Rel#:'.

This should give you the number with some extra white space, but you can trim it and parse it from there.

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.