The selenium test passed by Firefox. But When I'm trying to run it by IE, I get the error "Element xpath... not found"
string xpath = string.Format("xpath=(//table[@id='{0}']/tbody/tr[not(contains(@class,'{1}'))])[{2}]",tableId, CLASS_HIDDENROW,rowNumber);
string rowid = Selenium.GetAttribute(string.Format("{0}/@id",xpath));
I debugged it and found Selenium.GetXpathCount("//table[@id='328829']")
returns 0, which means IE even can't find the table with the id.
But when I use "View Source" on IE I found the following scripts
<table id="328829" class="scroll" cellpadding="0" cellspacing="0" style="z-index:1;"></table>
more information souce code(*.aspx)
<div id="<%=gridDef.gridId%>Wrapper" class="<%If Model.gridDefinitions.Count = 1 Then %>SummaryDiv<%Else%>HiddenRow<%End If %>" class="HiddenRow" style="position:relative;overflow:auto;overflow-y:hidden;">
<table width="100%">
<tr>
<td><span style="font-weight:bold;font-size:14px;color:#38AEF2"><%=gridDef.caption%></span></td>
<td align="right"><a style="cursor:pointer" onclick="$('#<%=gridDef.gridId%>tableWrapper').toggle();return false;"><%="vbeiHide/Show".TranslateHTML()%></a></td>
</tr>
</table>
<br />
<div id="<%=gridDef.gridId%>tableWrapper" name="<%=gridDef.gridId%>tableWrapper">
<table id="<%=gridDef.gridId%>" class="scroll" cellpadding="0" cellspacing="0" style="z-index:1;"></table>
<input type="image" src='../../Images/add2.gif' style="width:1px;height:1px;"/>
<input id="<%=gridDef.gridId%>_Create_Image" type="image" src="../../Images/add2.gif" title="<%="vbeiCreateANewSample".Translate() %>" onfocus="duplicateRow('#<%=gridDef.gridId%>','<%=gridDef.newTemplateId%>'); this.blur(); return false;" />
</div>
</div>
html when running
<div id="328829Wrapper" class="HiddenRow" class="HiddenRow" style="position:relative;overflow:auto;overflow-y:hidden;">
<table width="100%">
<tr>
<td><span style="font-weight:bold;font-size:14px;color:#38AEF2">Polluted Soil</span></td>
<td align="right"><a style="cursor:pointer" onclick="$('#328829tableWrapper').toggle();return false;">Hide / Show</a></td>
</tr>
</table>
<br />
<div id="328829tableWrapper" name="328829tableWrapper">
<table id="328829" class="scroll" cellpadding="0" cellspacing="0" style="z-index:1;"></table>
<input type="image" src='../../Images/add2.gif' style="width:1px;height:1px;"/>
<input id="328829_Create_Image" type="image" src="../../Images/add2.gif" title="Create a new sample" onfocus="duplicateRow('#328829','template_328829'); this.blur(); return false;" />
</div>
</div>
<script type="text/javascript">
jQuery("#328829").jqGrid({
url: "/Ordering/LoadData?gridId=328829",
editurl: "clientArray",
datatype: "json",
hoverrows : false,
mtype: 'POST',
loadui : "disable",
colNames: ['Options','Sample code (*)','Sample comments','SS Date Time Field (*)','IsTemplate','favourite name','favourite isShared','favourite sampleId'],
colModel: [{name: 'Options', index: 'Options', editable: false, hidden: false, sortable: false, resizable: false, edittype: 'text', width: 90, formatter:optionsFormatter },{name: 'Sample_Name', index: 'Sample_Name', editable: true, hidden: false, sortable: false, resizable: false, edittype: 'text', width: 150, editoptions: {maxlength: 50} },{name: 'Sample_Comments', index: 'Sample_Comments', editable: false, hidden: true, sortable: false, resizable: false, edittype: 'text' },{name: '51455962', index: '51455962', editable: true, hidden: false, sortable: false, resizable: false, edittype: 'text', editoptions: { dataInit:function(elem){attachDateTimePicker(elem);} } },{name: 'IsTemplate', index: 'IsTemplate', editable: false, hidden: true, sortable: false, resizable: false, edittype: 'checkbox' },{name: 'favourite_name', index: 'favourite_name', editable: false, hidden: true, sortable: false, resizable: false, edittype: 'text' },{name: 'favourite_isShared', index: 'favourite_isShared', editable: false, hidden: true, sortable: false, resizable: false, edittype: 'checkbox' },{name: 'favourite_sampleId', index: 'favourite_sampleId', editable: false, hidden: true, sortable: false, resizable: false, edittype: 'text' }],
imgpath: "/css/redmond/images",
height: "100%",
rowNum:-1,
altRows: true,
loadComplete: function() { loadComplete("#328829", 3);},
afterInsertRow: function(rowid, rowdata, rowelem) { rowInserted("#328829", rowid, rowdata); }
});
</script>
I also try to add the following scripts when setup, but it doesn't work.
if (browser == Browser.IE) {
selenium.UseXpathLibrary("javascript-xpath");
selenium.AllowNativeXpath("true");
}
Can someone tell me how to solve this problem? BTW, code is C#.