繁体   English   中英

在硒化物上定位元素

[英]locate an element on selenium ide

您好,我是Selenium IDE的新手,我有一个关于如何使用Selenium IDE定位特定元素的问题。

我有如下的HTML:

<div id="locator">
 <table class = "table-1">
 </table>
 <div class="something else">
 </div>
 <table class = "table-1">
  <tbody>
   <tr>
    <th>...</th>
    <td>
     <div class="adder">....</div>
    </td>
   </tr>
 </table>
</div>

问题是我想在第二个表格元素中找到div元素,有人能找出我该怎么做吗? 提前致谢。

使用伪类:nth-of-type

driver.FindElement(By.CssSelector("table.table-1:nth-of-type(2) > tbody > tr > td > div.adder"));

如果您使用Selenium IDE,请使用

css=table.table-1:nth-of-type(2) > tbody > tr > td > div.adder

请参阅Selenium IDE文档

当然,您也可以使用XPath代替CSS( http://docs.seleniumhq.org/docs/02_selenium_ide.jsp#locating-by-xpath )。

css选择器定位器支持css3,css3和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,:: after )

尝试这个....

driver.FindElement(By.CssSelector(“ div#locator table:nth-​​of-type(2)div.adder”));

我知道这很旧,但是上面提到的选择器是错误的。 CSS不支持某些伪类和伪元素。 不支持的列表如下。

css=table.table-1:nth-child(2) > tbody > tr > td > div.adder

6.7。 的CSS

CSS定位器策略使用CSS选择器在页面中查找元素。 Selenium支持CSS 1至3选择器语法,但CSS3名称空间和以下内容除外:

pseudo-classes       pseudo-elements

:nth-of-type          ::first-line

:nth-last-of-type     ::first-letter

:first-of-type        ::selection

:last-of-type         ::before

:only-of-type         ::after

:visited    

:hover

:active

:focus

:indeterminate

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM