简体   繁体   English

在硒化物上定位元素

[英]locate an element on selenium ide

Hello i am new for selenium IDE and i have a question about how to locate an specific element using selenium IDE. 您好,我是Selenium IDE的新手,我有一个关于如何使用Selenium IDE定位特定元素的问题。

I have HTML like following: 我有如下的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>

The problem is that i want to locate the div element in the second table element Could anyone figure me out how to do that? 问题是我想在第二个表格元素中找到div元素,有人能找出我该怎么做吗? Thanks in advance. 提前致谢。

use the pseudo class :nth-of-type : 使用伪类:nth-of-type

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

If you use the Selenium IDE, then use 如果您使用Selenium IDE,请使用

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

See the Selenium IDE documentation . 请参阅Selenium IDE文档

Of course you could also use XPath instead of css ( http://docs.seleniumhq.org/docs/02_selenium_ide.jsp#locating-by-xpath ). 当然,您也可以使用XPath代替CSS( http://docs.seleniumhq.org/docs/02_selenium_ide.jsp#locating-by-xpath )。

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选择器定位器支持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 )

Try this.... 尝试这个....

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

I know this is old, but the selector mentioned above is wrong. 我知道这很旧,但是上面提到的选择器是错误的。 CSS doesn't support some pseudo-classes and pseudo-elements. CSS不支持某些伪类和伪元素。 The unsupported ones are listed below. 不支持的列表如下。

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

6.7. 6.7。 CSS 的CSS

The CSS locator strategy uses CSS selectors to find the elements in the page. CSS定位器策略使用CSS选择器在页面中查找元素。 Selenium supports CSS 1 through 3 selectors syntax excepted CSS3 namespaces and the following: 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