【问题标题】:Using xpath to Identifying a child by an input with a parent div in Selenium IDE在 Selenium IDE 中使用 xpath 通过带有父 div 的输入来识别孩子
【发布时间】:2016-03-21 00:50:27
【问题描述】:

这是我的 HTML:

<div class="_15u9 _6a _6b">
<div class="uiPopover _6a _6b">
<a class="_p _55pi _5vto _55_p _2agf _4jy0 _4jy3 _517h _51sy _42ft" href="#" style="max-width: 200px;" role="button">
<span></span>
</a>
</div>
<input type="hidden" name="audience_page" value="432218040132603" style="background-color: rgb(255, 255, 255);">
</div>

我在 Selenium 中有这个,可以用 div 识别输入:

<tr>
<td>click</td>
<td>//div/descendant::input[@name='audience_page']</td>
<td></td>
</tr>

但我想点击子 div 中的链接。我试了一下:

<tr>
<td>click</td>
<td>//div/descendant::input[@name='audience_page']/div/a</td>
<td></td>
</tr>

有人能解释一下吗?我更喜欢不使用 ids 或 css 类。谢谢。

I looked at this post but I didn't think it quite answered the question...

【问题讨论】:

  • 你的a标签在哪里关闭?
  • 已添加,但下面的解决方案就像一种享受。谢谢;-)

标签: xpath css-selectors selenium-ide


【解决方案1】:

你可以试试这个方法:

//div[input/@name='audience_page']/div/a

基本上,XPath 将通过检查 child 元素inputname 属性来找到外部div。然后从这样的div,XPath 返回/div/a 元素。

【讨论】:

  • 正确。谢谢 ;-) 我以前从未见过 /@ 使用过 - 有趣!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-07-02
  • 1970-01-01
  • 2014-07-09
  • 2020-06-20
  • 2017-07-23
  • 2012-01-13
  • 1970-01-01
相关资源
最近更新 更多