'Problem with XPath query difference between IE and FF
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?
Solution 1:[1]
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:
//tr[@id[contains(.,'US7381548B2')]]//input
also, put the input in a <td>.
Solution 2:[2]
Try it with the double slash before the input resplaced with a single slash:
//tbody/tr[@id[contains(.,'US7381548B2')]]/input
Could be the XPath does not like it?
Solution 3:[3]
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.
Solution 4:[4]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Pete Duncanson |
| Solution 3 | knb |
| Solution 4 |
