Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 在selenium ide上查找元素_Html_Selenium - Fatal编程技术网

Html 在selenium ide上查找元素

Html 在selenium ide上查找元素,html,selenium,Html,Selenium,您好,我是selenium IDE的新手,我有一个关于如何使用selenium IDE定位特定元素的问题 我有如下HTML格式: <div id="locator"> <table class = "table-1"> </table> <div class="something else"> </div> <table class = "table-1"> <tbody> <tr>

您好,我是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>

...
....
问题是我想在第二个table元素中找到div元素 有人能告诉我怎么做吗?
提前感谢。

使用伪类
:类型的第n个

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

当然,您也可以使用XPath而不是css()

css选择器定位器支持所有css1、css2和css3选择器 除了css3中的命名空间之外,还有一些伪类(:n个类型, :n类型的最后一个,:类型的第一个,:类型的最后一个,:仅类型的, :已访问、:悬停、:活动、:焦点、:不确定)和伪 元素(::第一行,::第一个字母,::选择,::之前,::之后)

试试这个

driver.FindElement(By.CssSelector)(“div#locator table:第n个类型(2) 加法器)


我知道这是旧的,但上面提到的选择器是错误的。CSS不支持一些伪类和伪元素。下面列出了不受支持的

css=table.table-1:n个子(2)>tbody>tr>td>div.adder

6.7。CSS

CSS定位器策略使用CSS选择器查找页面中的元素。Selenium支持CSS 1到3选择器语法(CSS3命名空间除外)和以下内容:

<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>

感谢您的帮助,但我没有使用SeleniumWebDriver,我使用的是SeleniumIDE——一个基本的:)。你知道如何使用selenium IDE实现吗?感谢您的帮助,但我正在使用selenium IDE—一个基本的IDE:)。你知道如何使用selenium IDE实现吗?非常感谢你。这对我来说仍然不起作用,但您提供的文档非常有用,我将对此进行调查。