Exploring the code below:
<section id="section2" class="MightChange1 MightChange2">
<div id="dynamicIdxxx" class="dynamic1 dynamic2 dynamic3">
<div id="againDynamic" ..>
<div id="someDynamicCanBeRelayed" class="xyz">
<button id="dynmaicBtnxx" class="Cannot be relayed">
<span ....>
<span id="dynamic23" class="PartOfDoesntChange">
<bdi> show INTEGER more details</bdi>
How can we target the span element with the id 'dynamic23' based on the changing text within the bdi tags?
I could approach it like this: //*[@id='section2']//span/bdi[contains(text(),'more fields')]/ancestor::button")
The difficulty arises when the structure changes to:
<span id="dynamic23" class="PartOfDoesntChange">
<bdi> show INTEGER more details</bdi>
and sometimes without the bdi tag:
<span id="dynamic23" class="PartOfDoesntChange"> show INTEGER more details <span>
One approach is to handle both scenarios in Selenium by using two xpaths with and without bdi, then utilizing logical OR conditions. This way, we can still locate and interact with the desired element.
Are there more effective solutions for handling such cases, perhaps with CSS selectors?