Search code examples
javascriptseleniumxpathdrop-down-menudropdown

Uniquely identify elements in Auto Complete List which have similar text using Xpath


I need to select elements from an auto complete list which appears when you type something on the text field.

I have entered the text "Program NPL" and following two options show up

LD Program NPL -1 and
Program NPL - 4

I want to choose the second one but cannot use text()='' because the number at last is dynamic and can change in future.

I tried "starts-with" . It works for now but suppose if there is a value like "Program NPL ABC - 4". Then it won't work. Kindly suggest some solution. Thanks


Solution

  • This XPATH should work

    //*[starts-with(text(),'Program NPL -')]