XPath is not working using contains() and starts-with() functions for below ID


I have tried with:

//*[starts-with(@id,'u_')] - startswith
//*[contains(@id,'u_')]    -contains

Can anyone tell correct path of id after u is changing randomly and all other attributes like-classname,css are same ?

  • Edit & add your HTML code. – Bharat Mane Feb 5 '18 at 13:50
  • just want to know when there is value changing then what is the syntax or process to create xpath – Deepti Feb 5 '18 at 13:53
  • 3
    In the XPath you are using the hyphen, while in the id there is an underscore. Have you noticed it? – acejazz Feb 5 '18 at 14:09
  • 1
    @Deepti as above comment. Verify you have written dash (-) instead of underscore (_) in xpath. Please post your HTML tag so we can give more ideas. – Sagar007 Feb 6 '18 at 3:49
  • ya i know its just typo issue but still not working. – Deepti Feb 6 '18 at 16:57

Same like posted here.

//*[starts-with(@id,'u_0') and (@class='---')]

try with other attributes which are not changing continuously.

| improve this answer | |
  • ya thats the one option left. – Deepti Feb 6 '18 at 16:57
  • @Deepti-Is it works in your case, if yes accept the answer so that it will helps others too. – Bharat Mane Feb 7 '18 at 6:46

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.