Ember dropdown selenium xpath

断了今生、忘了曾经 提交于 2020-11-25 04:07:40

问题


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??


回答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]



回答2:


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:

  • How to click on the ember.js enabled button using Selenium and Python
  • Selenium - Finding element based on ember


来源:https://stackoverflow.com/questions/45653659/ember-dropdown-selenium-xpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!