Reputation: 13
HTML code:
<div id='abcd12$selenium450'>
where the numeric value ie 12 or 450 are changing frequently but the string part remains constant. I have tries with contains(), but I am confused bcz the xpath should contain abcd as well as selenium. Can anyone help here?
Upvotes: 1
Views: 48
Reputation: 2932
You can achieve that in multiple ways.
starts-with
and contains
CSS:div[id^='abcd'][id*='selenium']
starts-with
CSS:div[id^='abcd']
starts-with
and contains
xPath://div[starts-with(@id, 'abcd') and contains(@id,'selenium')]
If element is something like this then you can use multiple contains
HTML:
<div id='12abcd$selenium450'>
contains
and contains
xPath://div[contains(@id, 'abcd') and contains(@id,'selenium')]
Upvotes: 1
Reputation: 29382
You should use starts-with
and contains
both.
//div[starts-with(@id, 'abcd') and contains(@id,'selenium')]
Upvotes: 0