-2

enter image description here

Refer: Picture of elements of HTML screenshot I am trying to get XPATH

  1. //*[@id="pg:pbEdit:conlist"] or //select[@id="pg:pbEdit:conlist"]

  • Works but I want to be precise not multiple selections So
  1. I tried

//select[@id='pg:pbEdit:conlist' and @value='NEW_CONTACT']

  • This does not work (Please help me understand why as I see "value" is attribute.
  1. I tried this xpath

//select[@id='pg:pbEdit:conlist' and contains(text(),'James Baugh')]

Please can you advise me on what's going wrong.

2
  • //select whatever condition you are using in [] always selects select element. If you need to query its children you need to add something like //select[YOUR_CONDITION]/option[YOUR_CONDITION]
    – Alexey R.
    Jul 24 '20 at 10:26
  • Thank you @alexeyR. Much Appreciated
    – Protocoder
    Jul 25 '20 at 11:55
1
//select[@id='pg:pbEdit:conlist' and @value='NEW_CONTACT']

Refers to same element , that is the select tag

It will look for select tag with id pg:pbEdit:conlist and value NEW_CONTACT

But there is no tag like that , in your Dom select tag element has only ID

You should use:

   //select[@id='pg:pbEdit:conlist']/option[@value='NEW_CONTACT']

`

This ensures that the locator looks for select tag with the specified ID and then the child of that select tag that contains option has the tag name , and New contact as the value

0

I could get this working, I understand Option is the tag always thought part of Selet tag ..

//select[@id='pg:pbEdit:conlist']/option[contains(text(),'James')] However still keen to know why this should not work ` //select[@id='pg:pbEdit:conlist' and @value='NEW_CONTACT']

`

1
  • Thank you @PDHide. Thank you for your time, really appreciate
    – Protocoder
    Jul 25 '20 at 11:56
0

Sorry, as I was about to ask another question, Please may I know how to mark this question as answered. Thank you both

3
  • Refer this - meta.stackexchange.com/questions/5234/…
    – JAINAM
    Jul 26 '20 at 10:06
  • Protocoder, I hope the links JAINAM provided will help you. If you still need assistance please reply to this comment. Thank you!
    – corsiKa
    Jul 26 '20 at 15:46
  • Sorry could not login here, Yes I now I know how to mark as solved. Cheers
    – Protocoder
    Aug 13 '20 at 13:55

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