2

我想要做的是从列表中取出一个元素。我想获取链接中的文本,如果它包含正确的文本,请单击该链接。这是html代码:

<table>
     <tr>
        <td><a href='...'>I need help</a></td>
        <td><a href='...'>Oh hello</a></td>
        <td><a href='...'>Lorem ipsum</a></td>
     </tr>
</table>

我试过这个:

.click('table > tr > td > a:contains("I need help")')

但由于某种原因,它不起作用。

我不能使用这个:

.click('table > tr > td:nth-child(1) > a)

因为随着网站变大,将会添加更多的 tr 标签。

有任何想法吗 ?

4

2 回答 2

1

First of all, your HTML code is a bit twisted; a has to be a child of an element, not the way around. I suggest to read the MDN Docs regarding elements.

Regarding your problem with Dalek; Dalek uses the CSS selector engine of the browser that it executes. This will change in the future (Replaced by Sizzle as a unified selector engine), but I have no estimation when this future exactly will be.

Regarding the :contains() pseudo selector - As far as I know, this is gone. The current CSS3 spec has removed it & therefor you can't use that in your Dalek selectors.

于 2014-05-15T14:54:45.280 回答
0

我找不到检查链接文本的方法,但是如果您知道 href,请尝试改用它

.click('a[href="uniqueURL"]')
于 2014-05-15T12:30:16.753 回答