Reputation: 1214
I have a dynamic CSS selector which turns out to be the only selector I could use in my robot framework test. I there any way to use this selector maybe using regex?
Here is my selector :
#weekend11063281 > a:nth-child(1)
Any solution to get rid of the dynamic id part after #weekend will be welcome!
Thanks
Upvotes: 4
Views: 497
Reputation: 142
The only way that i can think of would be to have some other way of selecting the element(s) that you want. Lets say you have many elements with ids like #weekendxxxx and all of them are also using a name property weekend. You could now fetch all the weekend records in selenium by using the selector "name=weekend". Of course you would not need the quotes.
In our example above, we would get back more than one record. Remember, the name property is not unique in html. So this leaves you needing to do the nth child part that you had above.
Upvotes: 0
Reputation: 176
Below code should solve your problem
//HTML
<div id="weekend11063281">
<div>one</div>
<div>two</div>
</div>
//CSS
[id^='weekend'] > div:nth-child(1) {
color: red;
}
Upvotes: 4