Search code examples
c#seleniumnunitselenium-rcselenium-webdriver

Selenium Xpath issue verifying specific image at specific location - Internet Explorer 9 (IE9)


I’m new to Selenium and I have come across a test case issue in Internet Explorer 9 (IE9). I am using NUnit to run a test case to verify that a specific image is present in a specific location. The test case passes in Firefox and Chrome, but fails in IE9.

I have heard that IE has issues with Xpath, but could not find any definitive information on that subject. Is there any way to make this command work in IE using Xpath? Is there a better way I could run this verification without Xpath? Applicable info is below.

Note: I am also new to C#, so it could be a C# issue as well.

The command =

Assert.IsTrue(selenium.IsElementPresent("//html/body/form/div[8]/div[3]/div[3]/div[2]/div/div/table/tbody/tr/td/img[@src='images/4a00ac39-be42-46e0-8bd4-5cc786197357.jpg']"));

The HTML for the image =

<img style="padding-top: 3px; padding-bottom: 0px; background-color: transparent;" src="images/4a00ac39-be42-46e0-8bd4-5cc786197357.jpg">

The CSS path for the image =

html body.v4master form#aspnetForm div#s4-workspace div#s4-mainarea.s4-pr div#MSO_ContentTable.s4-ca div.s4-ba div.ms-bodyareacell div#ctl00_MSO_ContentDiv table.maintable tbody tr td img

Addtionally, the command works and the test case passes in IE9 when I drop the specific image verification part:

Assert.IsTrue(selenium.IsElementPresent("//html/body/form/div[8]/div[3]/div[3]/div[2]/div/div/table/tbody/tr/td/img"));

Solution

  • Best guess: IE is normalizing the SRC= attribute to the fully-qualified URL of the image. Try replacing img[src="...'] with img[contains(@src, '...'], which ought to work just as well with a relative or absolute URL.