问题
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