I am currently working on Eclipse using java bindings and i’m automating an e-commerce website. I am using Selenium 2 (Webdriver) to write my automation scripts and I’m having an issue trying to get a particular element via css. My preference is css because of the unstable nature of xpath (especially with the changes implemented on our site weekly). Can anyone please assist me? Thanks in advance. There are two buttons i need to click and are both similar. The first one is the continue button:
<td class="content" style="vertical-align: bottom; ; background: url(http://g-ecx.images-amazon.com/images/G/01/digital/video/avod-1-5/dp-sprite-total._V156422041_.png) no-repeat -3px -153px; padding: 0px 4px 0px 11px;"> Yes, continue with my purchase </td>
The second one is the cancel button:
<td class="content" style="vertical-align: bottom; ; background: url(http://g-ecx.images-amazon.com/images/G/01/digital/video/avod-1-5/dp-sprite-total._V156422041_.png) no-repeat -3px -181px; padding: 0px 4px 0px 11px;"> Cancel </td>
As you can see, they both have similar structures but only differ on the text. Now i can go as far as using this – css=td.content
but this brings both elements up and the script fails. What i need to do is input something that would use the text. Thank you in advance for your help
CSS selectors don’t work this way. There was something called :contains() but it was dropped. You could add a second class to each
tdelement like this:Then your CSS selector would look like this (in jQuery only because it’s so clean, this approach is standard CSS)