0

How to write xpath for the ember dropdown.

<ul id="ember-power-select-options-ember2473" class="ember-power-select-options ember-view" aria-controls="ember-power-select-trigger-ember2473" role="listbox"> <li class="ember-power-select-option" aria-selected="false" aria-current="false" data-option-index="0" role="option">Option A

Since the ember id changes, how can i write xpath??

UnknownN
  • 13
  • 3

2 Answers2

1

With xpath:

//ul[contains(@id, 'ember-power-select-options-ember')]

With css:

ul[id*='ember-power-select-options-ember']

Other css:

ul.ember-power-select-options[role=listbox]
lauda
  • 4,153
  • 2
  • 14
  • 28
0

The value of the value of the id attribute will keep changing dynamically, everytime you access the AUT(Application Under Test). Hence to interact / click the dropdown you need to construct dynamic Locator Strategies as follows:

  • cssSelector:

    ul.ember-power-select-options.ember-view[id^='ember-power-select-options-ember']
    
  • xpath:

    //ul[starts-with(@id, 'ember-power-select-options-ember') and @class='ember-power-select-options ember-view']
    

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352