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.

Thursday 6 November 2008

Use selenium to create screenshot

I just stunbled across selenium as a tool to take screenshot.
Thuis could be useful for anything.

In my case i used it to take the screenshot of a page just before it throws an error in my selenium test. and that i could have a look and investigate what the problem might have been.

very simple command and the great thing is it can be easily used for screenshots of a page across different browsers.

browser.CaptureEntirePageScreenshot("C:\\actual _path_to_where_you_want the_file _placed\\screenshot.png");

Selenium and Javascript events

Have you ver been in situattion when youhave typed a value into a text box and you expect a
Javascript event to be called such as "OnBlur"

welll selenium has a method "FireEvent" which triggers the event for you, but then the trick is you have to strip the "on" and name for the event wouldbe "OnBlur"

I guess abit of example would make more sense, lol.
This is what my html look like

<input type="text" value="" onblur="JavaScript:ValidateSimpleMail(true);" size="25" name="EMAIL_1" id="EMAIL_1"/>

selenium command to type into an email box, which doesnt fire the event attached to the text box

browser.Type("EMAIL_1", "sam@sam.com");

The work around is to use selenium to fire the event after it has typed in the textbox
FireEvent(locator, eventName) which in my case is

browser.FireEvent("EMAIL_1", "blur");

Monday 3 November 2008

Selenium: Xpath locator can not be used as Option Locator

In my new job been doing a lot of selenium and i needed to scroll through the list of
options in a select element and click on a particular options.

i have initially used the browser.DoubleClick

browser.DoubleClick("xpath=//select/option[child::text()='Option_Label']");)

But then this didnt work because selenium doesn't have the functionality to scroll down the select element in other to make my desired option visible.

Looking through the selenium api, i have used another method, which take in two parameters, the select locator and the option locator.

so i used:

browser.Select("xpath=//select", "xpath =//option[child::text()='Option_Label']");

that hasnt work either as the option locator type cannot be xpath. it has to be a label, id, atrribute, name or any other html locator

so i have done

browser.Select("xpath=//select", "label=Option_Label");

which in myown opinion i think is good as it is robust for a selenium test.