How to use regular expressions between Selenium CSS selector code?

I am having trouble using regex between the unique id of an element.

Here's the html code

<td align="left" style="vertical-align: top; ">   
 <span class ="radiobutton"   id="mainId:gen_id_12e3:radiospan1e">      
   <input type="radio" name="radio1" value="on" id="radio1" tabindex="0" checked>       
     <label for="id-2024">Yes</label>

      

Using xpath, I used the selenium command below with (. *) Between the element id which works great.

    selenium.click("xpath=//span[@id, 'mainId.*radiospan1e']");

      

However, I cannot do the same in CSS as they have $ for the end of the id, ^ for the start and * anywhere on the page, but I want the id that starts with mainId with some regex and ends with a unique id ...

Any help would be appreciated.

+3


source to share


1 answer


CSS doesn't support regular expressions in general, but if you just want to fit the entire middle part from your ID, it's actually quite doable in CSS, as shown in this answer .

Given your code, you can use:



selenium.click("css=span[id^='mainId'][id$='radiospan1e']");

      

+4


source







All Articles