tags:

views:

37

answers:

1

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#.

A: 

You had a typo in your debug line, so if that's the actual line you used it would have returned 0 even for Firefox. You could try the following in IE to see if can see the table: selenium.isElementPresent("id=328829")

Another thing you could try is altering your XPath slightly. Without seeing more of your HTML it's difficult to make a suggestion, but you could try the following:

xpath=id('328829')/descendant::tr[not(contains(@class,'hidden'))][1]

I've seen problems where the tbody doesn't exist depending on the browser under test, so using /descendant::tr might help.

Dave Hunt
the result of "selenium.isElementPresent("id=328829")" is false. And the element not found error also happened after I just simplified the code as: string xpath = string.Format("xpath=//table[@id='{0}']",tableId); string rowid = Selenium.GetAttribute(string.Format("{0}/@id",xpath)); I add more html code in my questions BTW:"<div id="328829tableWrapper...>"is able to get
Note sure if it makes a difference but your `id` attributes are invalid. They should start with a letter ([A-Za-z]). See http://www.w3.org/TR/html401/types.html#type-name
Dave Hunt
I think you are right since I use UseXpathLibrary("javascript-xpath").Thank you very much!
Since I can't modify the source code of the problem, I delete the code "UseXpathLibrary("javascript-xpath")" in selenium test which makes the running very slow.Error "Function timed out" may happen sometimes when I debug.Is it possible to set the max timeout for debug ?