XPath to select CSS

I have the following xpath statement in selenium test:

//tbody/tr[td/span[text()='IPODate']]/td[4]/input 

It gets what I want, but my tests in IE6 are very slow. Does anyone know how I will do the same selector as the CSS selector? I think I understand how to make each of them with an exception with the text () = "IPODate" part.

As requested, here is an example of a table I'm trying to select from:

 <table cellspacing="0" cellpadding="4" border="0" id="tblResearchItems" class="coolTable SingleItem"> <tbody> 

.... many many lines

 <td> <input type="button" value="A" onclick="sA('secm.Company', 'IPODate', 299)" class="RButton NarrowButton2 A Show_N"/> </td> <td class="TCN"> <span class="CN">IPODate</span><f/> </td> <td> <g/> </td> <td class="TCV VerticalAlign"> <input type="text" value="" onfocus="stLT(); hideLB(true)" onblur="mustBeDate($(this));" class="UpUI_Y date NDD hasDatepicker" id="dp1260909771780"/> <img class="ui-datepicker-trigger" src="../images/calendar.gif" alt="..." title="..."/> <div/> </td> </tr> 

... many other lines ...

in this example, only one row has an IPODate cell.

+1
source share
1 answer

CSS locator css=span.CN for a range in which there is IPODate text.

Saucelabs have a good explanation of how this works on their blog.

UPD: Unfortunately, CSS will not parse the entire tree as it moves up and down until it finds what it is after. This is the main reason why XPath is so slow. CSS finds the element and then can move sideways through the DOM. The CSS below will find the input field, which after TD has class=TCN , which contains your range with the text in the table.

CSS: table > tbody > tr > td.TCN + td + td > input

+4
source

All Articles