使用CSS选择器通过Selenium访问特定的表行 [英] Using CSS selectors to access specific table rows with selenium

查看:80
本文介绍了使用CSS选择器通过Selenium访问特定的表行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我具有以下HTML:

If I have the following HTML:

<tbody id="items">
<tr><td>Item 1</td></tr>
<tr><td>Item 2</td></tr>
<tr><td>Item 3</td></tr>
<tr><td>Item 4</td></tr>
<tr><td>Item 5</td></tr>
<tr><td>Item 6</td></tr>
</tbody>

我如何将CSS选择器与Selenium一起使用来访问第4项(或实际上我想要的任何项)?

How would I use CSS selectors with Selenium to access Item 4(or really any item I wanted)?

推荐答案

您可以使用nth-child选择器:

You can use nth-child selector:

#items tr:nth-child(4) {color:#F00;}

实时示例: https://jsfiddle.net/7ow15mv2/1/

但是不知道它是否可以与Selenium一起使用.

But no idea if it works with Selenium.

但是根据文档,应该如此.

But according to docs it should.

当前,css选择器定位器支持所有css1,css2和css3选择器,但css3中的名称空间,一些伪类(:nth-​​of-type,:nth-​​last-of-type,:first-of-type,:last -of-type,:only-of-type,:visited,:hover,:active,:focus,:indeterminate)和伪元素(:: first-line,:: first-letter,:: selection,:: before , ::后).

Currently the css selector locator supports all css1, css2 and css3 selectors except namespace in css3, some pseudo classes(:nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, :only-of-type, :visited, :hover, :active, :focus, :indeterminate) and pseudo elements(::first-line, ::first-letter, ::selection, ::before, ::after).

这篇关于使用CSS选择器通过Selenium访问特定的表行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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