My blog has moved!
You should be automatically redirected in 5 seconds. If not, visit http://samueladesoga.wordpress.com and update your bookmarks.

Saturday 8 November 2008

Internet Explorer doesnt handle xpath to locate images exceptionally well

So i have been doing a lot of selenium and the website i am trying to automate test for
doesnt have a lot of element with id, name, or any other HTML attributes that makes selenium testing a bit easier.

So i have been using of xpath, my intent was to click on an image and i have used the src attribute of the image element.

so my original command,

selenium.click ("xpath=//img[@src="location/of/image/on/disc"]");

This works excellently on firefox but on IE, i keep getting the error "Element not found!"

so after several tries, this definitely work on both IE and firefox ......

selenium.click ("xpath=//img[@contains(@href, "google.com")]");
The second parameter of the xpath "contains" a segment of the link that the image element points to.Note that the img element has a href and that is why i am able to use the "contains" method of the xpath to locate the img.

No comments: