zhaojing
zhaojing

Reputation: 635

Why selenium locating element by Xpath failed in IE, but it works wll in firefox?

I have my selenium automation test scripts run in firefox, and it works well. Now I want to run the scripts in IE, it seems it failed on the step of locating an element in GUI. It seems selenium can't find the element in GUI while firefox can easily find it.

String servicenameidtext = "//table[@id='release_hostsProcesses_list']/tbody/tr[2]/td[1]/td";
Selenium.getText(servicenameidtext );

In fact, the scripts is recorded by selenium-IDE, and I have check about the Xpath, I think there is no problem of the element. But why selenium failed on this step in IE?

Could anyone tell me the reason? And how to solve the problem when running test in IE? Thanks a lot!

I want to locate the element "alarmlm" from the GUI by

String servicenameidtext = "//table[@id='release_hostsProcesses_list']/tbody/tr[2]/td[1]/td";

P.S:  The html of the part:
<tbody><tr class="form-title"><td colspan="3"><a href="javascript:void(0);" onclick="javascript:ChangeVisibility( 'release_hostsSoftwareInformation' ); return false;"><img src="img/minus.png" title="-" alt="-"></a>&nbsp;<b>Software Information</b>
</td></tr><tr><td><div id="release_hostsSoftwareInformation_internal">
<table id="release_hostsProcesses_list" border="0" width="100%" class="Processes_list"><tbody>
<tr class="title-column"><td><b>Service Name</b></td><td><b>Summary</b></td><td><b>Description</b></td><td><b> Version </b></td><td><b>Release</b></td><td colspan="2"><b>Installation Date</b></td></tr><tr><td>alarmlm</td><td>mpm</td><td>MultiPlatformManagement tools</td><td>4.0.12</td><td>5</td><td>Wed 10 Nov 2010 04:23:52 AM CST</td></tr><tr><td>annlabclient</td><td>Annlab Client</td><td>Annlab Client</td><td>5.0.13</td><td>23</td><td>Wed 10 Nov 2010 04:23:57 AM CST</td></tr><tr><td>annlabserver</td><td>Annlab Server</td><td>Annlab Server</td><td>5.0.13</td><td>23</td><td>Wed 10 Nov 2010 04:23:57 AM CST</td></tr><tr><td>recoveryalarmlm</td><td>mpm</td><td>MultiPlatformManagement tools</td><td>4.0.12</td><td>5</td><td>Wed 10 Nov 2010 04:23:52 AM CST</td></tr><tr><td>recoverystatlm</td><td>mpm</td><td>MultiPlatformManagement tools</td><td>4.0.12</td><td>5</td><td>Wed 10 Nov 2010 04:23:52 AM CST</td></tr><tr><td>mrfctrl</td><td>MRF Controller</td><td>mrfctrl - including sipproxySubsystem</td><td>1.4.0.5</td><td>1</td><td>Wed 10 Nov 2010 04:24:00 AM CST</td></tr></tbody></table></div></td></tr></tbody>

Thanks to all, the problem is solved. The cause is: the html in firefox and IE are not the same. Strange.

Upvotes: 1

Views: 2481

Answers (4)

user3487861
user3487861

Reputation: 350

In this Case we can do 1 thing

To Inspect Elements for Internet Explorer IE Developer Tools is available and for FireFox Firebug

We can compare both Inspections Derive the XPath/CSS from IE Developer Tools for the Object.

Use and Check is it working in both IE and FF

If it works Fine Otherwise Conditionally we can use the corresponding XPath According to Browsers.

Upvotes: 0

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243599

Maybe, due to a default namespace?

The error explanation is in the data you haven't shown us -- what about providing the (x)Html text?

UPDATE:

Now the OP has provided the source (x)Html document. The provided XPath expression:

//table[@id='release_hostsProcesses_list']/tbody/tr[2]/td[1]/td

doesn't select the required element simply because a td is never a child of another td, but this is exactly what this XPath expression is looking for -- it ends with:

td[1]/td

Upvotes: 2

Sergii Pozharov
Sergii Pozharov

Reputation: 17858

Try to use all lowercase characters in id field:

String servicenameidtext = "//table[@id='release_hostsprocesses_list']/tbody/tr[2]/td[1]/td";
Selenium.getText(servicenameidtext );

Should work in both FF and IE

Upvotes: 1

knb
knb

Reputation: 9383

you could try to check out what the text value is directly in IE by appending /text() to the xpath expression. Maybe it finds the empty string?

String servicenameidtext = "//table[@id='release_hostsProcesses_list']/tbody/tr[2]/td[1]/td/text()";
alert("found:"  + servicenameidtext);

My two cents,

Upvotes: 1

Related Questions