【问题标题】:Unable to locate element from webdriver whereas IDE locates it无法从 webdriver 找到元素,而 IDE 找到它
【发布时间】:2014-07-07 16:48:02
【问题描述】:

请在下面找到代码:

<table class="cctable" width="100%" border="0" cellspacing="0" cellpadding="2" tabindex="0" summary="Content">
<thead id="Header">
<tbody>
<tr style="height:1px">
<tr style="height:1px">
<tr style="height:1px">
<tr style="height:1px">
<tr style="height:1px">
<tr style="height:1px">
<tr style="height:1px">
<tr style="height:1px">
<td class="tableText" nowrap="" height="10">
<td width="1" height="15">
<td class="tableText" nowrap="" height="10">
<td width="1" height="15">
<td class="tableText" width="100%" height="10" wrap="true" style="background-color: transparent;">
<a href="/tarf/servlet/dispatch?b_action=xts.run&m=portal/cc.xts&m_folder=iED96C06121E44804B62901EB41BCAEC2">**Hyper-V**</a>
</td>
<td width="1" height="15">
<td class="tableText" width="200" nowrap="" height="10">
<td width="1" height="15">
<td class="tableText" width="170" nowrap="" height="10">
</tr>
<tr style="height:1px">
<tr style="height:1px">
<tr style="height:1px">
<tr style="height:1px">
<tr>
</tbody>
<tfoot></tfoot>
</table>

我正在尝试点击用户界面上的“Hyper-V”链接。

我尝试了 css、xpath、name、id,所有可能的定位器,当我尝试通过 selenium IDE 2.5.0 找到它时,所有定位器都可以工作。当我评估时,元素会闪烁。

但是,当我在我的 webdriver 脚本中放置相同的定位器并尝试定位它时,它每次都会抛出“NoSuchElementException”。有人可以建议我如何处理吗? 如何知道 Selelnium 是否支持在我们的 UI 上定位元素,或者我们是否有任何限制。

让我知道你的建议/想法。

提前致谢。

【问题讨论】:

    标签: selenium ide webdriver


    【解决方案1】:

    我通过 xpath 进行了尝试,它工作了 //a[text()='**Hyper-V**'] FireFox + FireBug + FirePath

    IMG:http://cdn.joxi.ru/uploads/prod/2014/07/07/333/7cc/fea637f96e0087660354dcce74cdea55e17fdf16.jpg

    【讨论】:

    • 嗨,Andiran,感谢您的回复。
    • 嗨安德里安,感谢您的回复。我可以通过 usnig xpath 或 css 以这种方式定位我的元素,但是我担心的是,当我将此 xpath 或 css 放入我的 webdriver 代码并执行它时显示“线程“主”中的异常 org.openqa.selenium.NoSuchElementException: Unable to定位元素:{"method":"xpath","selector":"//a[text()='Hyper-V']"} 不确定这是否是我的限制支持 selenium webdriver 的应用程序,因为这适用于 Selenium IDE,并且能够单击具有上述 xpath 的定位元素。
    • 试试 //a[contains(text(),'Hyper-V')]
    • 嗨 Andrian,谢谢 尝试使用给定的 xpath,即使这在执行时也不起作用,得到相同的错误。
    • 也许你的元素不是动态的,当你搜索你的元素时尝试打印页面源并在那里搜索你的 Hyper-V,driver.getPageSource(),如果你找不到然后添加等待它的时间。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-29
    • 1970-01-01
    • 1970-01-01
    • 2014-07-13
    • 2015-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多