NotMyself
NotMyself

Reputation: 30047

XPath to CSS Selector

I have the following xpath statement in a selenium test:

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

It gets what I want but my tests are painfully slow in IE6. Anyone know how I would do the same selector as CSS selectors? I think I understand how to do each of these with exception to the text()="IPODate" part.

As requested here is an example of the table I am trying to select from:

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

.... many many rows

<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 many more rows...

in this example only one row has the IPODate cell.

Upvotes: 1

Views: 6865

Answers (1)

AutomatedTester
AutomatedTester

Reputation: 22418

the CSS locator is css=span.CN for the span that has the text IPODate in it.

Saucelabs have a good explanaton of how it works on their blog

UPD: Unfortunately CSS won't parse the entire tree when move up and down till it finds what it is after. This is the main reason why XPath is so slow. CSS finds an item and then can move laterally through the DOM. The CSS below will find the input box that is after the TD that has class=TCN which holds your span with text in the table.

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

Upvotes: 4

Related Questions