Wednesday, May 9, 2012

How to automate lost focus through selenium.

Sometimes we face a problem while automating the form submit. All of the form fields are having some action on their lost focus.
The onblur event occurs when an object loses focus.
For example : I have two fields First Name and Last Name. When i enter first name and press tab then it loses its focus and onblur function gets called.
and its calls upperCase and it changes the first name in Upper case.
the same case with Last Name. When i enter last name and press tab it calls blur function lowerCase and changes the letters in lower case.

But the problem in automation is i cant automate lost focus. when we type in first name and last name it simply types in first name and last name text box.
It does not call onblur function upper case and lower case and does not change the letter respectively.

so, fireEvent is a special command in selenium which helps in automating onblur function.

this is html of the element and blur javascript functions :






Enter your First Name:


Enter your Last Nast:



Now in Selenium, Do this :


 
How this works is :

First this will type "ridihima" in First Name and then selenium.fireEvent("fname", "blur"); this will call the onblur fuction "upperCase()" which changes the First Name in upper case "RIDIHIMA".
then it types in Last Name and then selenium.fireEvent("lname", "blur"); which means it will press tab and lost the function and on the lost focus it calls blur function lowerCase which changes the Last Name in lower case.

Tuesday, May 8, 2012

Verify value in drop down list through regular expression

To find element drop down is easy but to find a drop down having some specific value in their list is difficult.
Go to www.ebay.in you will see there is drop down along with search text box.
How to verify a specific value "Collectibles" is in drop down list. Doing testing in Selenium, It will come as :  

How to select the value in drop down using regular expression.

There are situation when we need to select the drop down value with some partial text .
With the help of regular expression we can select the drop down value.