![](/img/trans.png)
[英]Unable to locate any html element in an iFrame with Selenium IDE
[英]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.