1
  • When I search with input a -- the page displays me a link with linktest html.
  • When I search with input b -- the page displays me a link with linktest xml.
  • When I search with input c -- the page displays me a link with linktest pdf.

I have different linktests for different inputs

on locating the link element, the xpath shows

//*[contains(text(),'html')]
//*[contains(text(),'xml')]
//*[contains(text(),'pdf')]

I need generic xpath. Tried by.tagName("a") any other way other than preceeding and following logic.

1

You can use logical expressions in xpath, like and or or. So to match an element with text: pdf, html or xml you could use a following exception:

//a[contains(text(),'html') or contains(text(),'xml') or contains(text(),'pdf')]
  • I have 48 such types,may be in future some more may be added. – zaki uddin Dec 21 '18 at 7:18
  • @zaki Based on the question I though that there are only those 3 you have mentionded. In case of 48 it would be good from you to share the HTML source as of the links to see if we have other possibilities for a generic expression. – Bence Kaulics Dec 21 '18 at 10:33

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.