IE和FF的XPath查询差异问题
我一整天都在与这个问题作斗争,但没有任何结果。我使用 selenium webdriver 并希望通过 xpath: 获取两个字符串:
<input id="FB_childRec1_0" type="hidden" value="child12_0,child22_0,child13_0,child23_0,child14_0,child24_0" size="1"/>
并
<input id="FB_childRec4_0" type="hidden" value="child15_0,child25_0,child16_0,child26_0,child17_0,child27_0,child18_0,child28_0,child19_0" size="1"/>
从这段代码中:
<tbody>
<input id="cidChild1_0" type="hidden" value="T3$PATENT$US7381548B220080603"/>
<input id="cidChild1_0" type="hidden" value="T3$PATENT$US7381548B220080603"/>
<tr id="FORWARD_1US7381548B220080603_0" class="alternate" style="" name="childTR">
<td class="tborder leftAlignment" rowspan="1" style="width:1%">
<td class="tborder leftAlignment vTop" rowspan="1" style="width:1%">
<input id="FB_childRec1_0" type="hidden" value="child12_0,child22_0,child13_0,child23_0,child14_0,child24_0" size="1"/>
<td class="tborder leftAlignment vTop" rowspan="1" style="width:1%">
<td class="frmData tborder vTop" align="left" rowspan="1" colspan="5">Forward Citation - (Displaying 3 forward citations)</td>
</tr>
<input id="cidChild4_0" type="hidden" value="T3$PATENT$US7381548B220080603"/>
<tr id="BACKWARD_4US7381548B220080603_0" class="alternate" style="" name="childTR">
<td class="tborder leftAlignment" rowspan="1" style="width:1%">
<td class="tborder leftAlignment vTop" rowspan="1" style="width:1%">
<input id="FB_childRec4_0" type="hidden" value="child15_0,child25_0,child16_0,child26_0,child17_0,child27_0,child18_0,child28_0,child19_0" size="1"/>
<td class="tborder leftAlignment vTop" rowspan="1" style="width:1%">
<td class="frmData tborder vTop" align="left" rowspan="1" colspan="5">Backward Citation - (Displaying 14 backward citations)</td>
</tr>
</tbody>
我使用这样的 xpath 查询: //tbody/tr[@id[contains(.,'US7381548B2')]]//input< /code>
在代码中它是:
driver.FindElements(By.XPath("//tbody/tr[@id[contains(.,'" + queryArray[i] + "')]]//input"));
Firefox 中一切正常,我可以获得 2 个元素。但在 IE 中 FindElements() 没有找到任何东西。我在IE8和IE9上都试过了,没有任何结果。我已将 Selenium WebDriver 更新到 2.0.0 但没有帮助。然后我想也许应用程序为 FF 和 IE 提供了不同的源。所以我从IE中保存页面并用FF打开它。 Firepath 显示了两个匹配项,因此来源是相同的。
这一切都让我认为这是硒的一些错误,因为我第二次遇到这样的问题。有很多主题都有类似的问题 - xpath 查询在 FF 中有效,但在 IE 中不起作用。但我找不到任何原因。
是什么导致了硒如此奇怪的行为?我应该怎么做才能解决这个问题?
I've been fighting this problem all the day but without any results. I use selenium webdriver and want to get two strings by xpath:
<input id="FB_childRec1_0" type="hidden" value="child12_0,child22_0,child13_0,child23_0,child14_0,child24_0" size="1"/>
and
<input id="FB_childRec4_0" type="hidden" value="child15_0,child25_0,child16_0,child26_0,child17_0,child27_0,child18_0,child28_0,child19_0" size="1"/>
from this code:
<tbody>
<input id="cidChild1_0" type="hidden" value="T3$PATENT$US7381548B220080603"/>
<input id="cidChild1_0" type="hidden" value="T3$PATENT$US7381548B220080603"/>
<tr id="FORWARD_1US7381548B220080603_0" class="alternate" style="" name="childTR">
<td class="tborder leftAlignment" rowspan="1" style="width:1%">
<td class="tborder leftAlignment vTop" rowspan="1" style="width:1%">
<input id="FB_childRec1_0" type="hidden" value="child12_0,child22_0,child13_0,child23_0,child14_0,child24_0" size="1"/>
<td class="tborder leftAlignment vTop" rowspan="1" style="width:1%">
<td class="frmData tborder vTop" align="left" rowspan="1" colspan="5">Forward Citation - (Displaying 3 forward citations)</td>
</tr>
<input id="cidChild4_0" type="hidden" value="T3$PATENT$US7381548B220080603"/>
<tr id="BACKWARD_4US7381548B220080603_0" class="alternate" style="" name="childTR">
<td class="tborder leftAlignment" rowspan="1" style="width:1%">
<td class="tborder leftAlignment vTop" rowspan="1" style="width:1%">
<input id="FB_childRec4_0" type="hidden" value="child15_0,child25_0,child16_0,child26_0,child17_0,child27_0,child18_0,child28_0,child19_0" size="1"/>
<td class="tborder leftAlignment vTop" rowspan="1" style="width:1%">
<td class="frmData tborder vTop" align="left" rowspan="1" colspan="5">Backward Citation - (Displaying 14 backward citations)</td>
</tr>
</tbody>
I use such xpath query: //tbody/tr[@id[contains(.,'US7381548B2')]]//input
In code it is:
driver.FindElements(By.XPath("//tbody/tr[@id[contains(.,'" + queryArray[i] + "')]]//input"));
Everything works perfect in firefox and i can get 2 elements. But in IE FindElements() does not find anything. I've tried it on IE8 and IE9 without any result. I've updated Selenium WebDriver to 2.0.0 but it does not help. Then I think maybe application gives different source for FF and IE. So I save the page from IE and open it with FF. Firepath shows me two matches, so the source is the same.
That all makes me think that it is some bug of selenium, because i face such kind of problem for second time. There are a lot of topics with similar problem - xpath queries works in FF but does not work in IE. But I can't find any cause of this.
What can cause such strange behaviourof selenium? And what should I do to fix the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
FF 和 IE 中 DOM 的设置方式存在一些差异,特别是 tbody 标签。尝试从 XPath 中删除
tbody
:另外,将
input
放入中。
There are some differences with how the DOM is set up in FF and IE, particularly with the tbody tag. Try removing the
tbody
from the XPath:also, put the
input
in a<td>
.在用单斜杠替换输入之前尝试使用双斜杠:
可能是 XPath 不喜欢它?
Try it with the double slash before the input resplaced with a single slash:
Could be the XPath does not like it?
IE8支持document.documentElement.contains(),但不支持document.contains()。
也许这对于 selenium 和 IE 的交互来说是令人困惑的。
尝试将 allowedNativeXpath() 属性设置为 false。
IE8 supports document.documentElement.contains(), but not document.contains().
Maybe this is confusing to both selenium and IE interacting.
Try setting the allowNativeXpath() Property to false.
步骤一:
获取 FB_childRec1_0 的 2 个输入控件定位器的定位器
:css=.alternate[id*='FORWARD'] > input[id*='FB_childRec']
FB_childRec4_0 定位器:css=.alternate[id*='BACKWARD'] > input[id*='FB_childRec']
所以从上面的定位器可以完成任何操作。
Step 1:
Get the Locators for the 2 Input Controls
Locator for FB_childRec1_0:css=.alternate[id*='FORWARD'] > input[id*='FB_childRec']
Locator for FB_childRec4_0:css=.alternate[id*='BACKWARD'] > input[id*='FB_childRec']
So From the Above Locators What ever operations can be done will be done.