XPath到CSS选择器 [英] XPath to CSS Selector

查看:341
本文介绍了XPath到CSS选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在selenium测试中有以下xpath语句:

I have the following xpath statement in a selenium test:

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

测试在IE6中很慢。任何人知道我将如何做相同的选择器作为CSS选择器?我想我知道如何做这些每一个,除了text()=IPODate部分。

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...

在此示例中,只有一行具有IPODate单元格。

in this example only one row has the IPODate cell.

推荐答案

CSS

Saucelabs有一个很好的解决方案,它的定位符是 css = span.CN 解释其如何在其 blog

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

UPD:
不幸的是,CSS不会解析整个树向上和向下,直到它找到它是什么。这是XPath很慢的主要原因。 CSS找到一个项目,然后可以横向移动通过DOM。下面的CSS将会找到 TD 之后的输入框,其中包含 class = TCN 在表中。

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>输入

这篇关于XPath到CSS选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆