如果我有以下 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(或我真正想要的任何元素)?
最佳答案
您可以使用第 n 个子选择器:
#items tr:nth-child(4) {color:#F00;}
实例:https://jsfiddle.net/7ow15mv2/1/
但不知道它是否适用于 Selenium。
但根据文档,它应该。
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 - 使用 CSS 选择器访问带有 selenium 的特定表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4494708/