Here the id=popupY8cuUiMiDU
is dynamic.I need to get the Y value from span but there are multiple listbox with the same span attribute taking Y option.
How can I select from listbox as there is no unique attribute?
-
You can select using class attribute into the xpath– Mohamed Sulaimaan SheriffCommented Aug 29, 2020 at 4:20
1 Answer
There're a few options.
getting the element by what's not dynamic in its id
//div[contains(@id, "popup")]
using CSS
.ui-dropdown-panel.ui-widget-content.ui-corner-all.ui.shadow
asking developers to build in a unique test id for you
e.g. there could be something like
data-test-id=popup
, then you'd use a css selector like so:[data-test-id=popup]
There could be more options, you can get more creative etc. But I'd keep it as simple as possible, which promotes maintainability and readability.