I have this problem with locating dynamic buttons.
It's a search for ferries, and for example, outbound ferry is selectedDetailsRadio_1_4_1
and inbound is selectedDetailsRadio_1_4_2
. These are fine and easy to locate.
However, depending on the date the search can return several departures the same day, or economy/flex/business class selections.
Then the buttons change name to to selectedDetailsRadio_1_5_1
, ...1_6_1
, ...1_7_1
, (and for inbound: 1_5_2
/1_6_2
/1_7_2
) and so on. And since selectedDetailsRadio_1_4_1
isn't on the page anymore, the test fail.
So I need to wildcard the number which is dynamic and changes, I think, but I cannot figure out how. I've Googled for this, but all I can find is starts-with
and contains
for testing, and since I need a single digit in the middle of the id to be wildcarded, I don't think contains
will do it.
Can anyone point me in the correct direction?
Edit: Code example:
<li>
<input id="selectedDetailsRadio_1_5_2" type="radio" onclick=" enableDisable(1,'2','5'); changeSailing(1,'to 12 mars 2015 08:00','to 12 mars 2015 11:45','2015-03-12T08:00:00'); " value="1,5,2," title="1i5j2f08:00t" name="Search/FerryInformation/SelectedDetailsRadio$1$" tabindex="18"/>
<input id="timeFormattedDep_1_5_2" type="hidden" value="to 12 mars 2015 08:00" tabindex="19"/>
<input id="timeFormattedArr_1_5_2" type="hidden" value="to 12 mars 2015 11:45" tabindex="20"/>
<input id="milliSecsDep_1_5_2" type="hidden" value="1426143600000" tabindex="21"/>
<input id="milliSecsArr_1_5_2" type="hidden" value="1426157100000" tabindex="22"/>
<label for="outbound-economy1">
<strong>
<span id="moneyAmount">1076</span>
NOK
</strong>
Flex
</label>
</li>
_1_5_2
etc. are unique, right? A XPath like this should work for the first element and similar XPaths for the others://input[contains(@id, 'selectedDetailsRadio')]