Examples of Scripts for Automation – Selenium Training
Public class test1 :
Public static void main ( string[ ] args) throws interrupted exception .
// Launch site.
WebDriver obj= new FirefoxDriver();
obj.get ( ” http://newtours.demoaut.com/”);
Thread.sleep (5000 );//wait 5 seconds
//click register link
obj. find element ( By . link text (“REGISTER”)). Click ( );
Thread . sleep (5000);
// Fill fields
obj. find element ( By.name (” First name”)). send keys (“xyz”).
obj. find element (By.name(“Last name”)). send keys( “abc”);
obj. find element ( By.name(” Phone”)). send keys ( “9999999999”);
obj. find element ( By.name(“User name”)). send keys (“xyzuzzamaa@gmail “);
obj. find element (By.name(“address 1″)). send keys ( ” Namitha Hormony “);
obj. find element (By.name(“address 2″)). send keys (” moulaali “);
obj. find element (By.name(“city “)). send keys (” Hyderabad”);
obj. find element (By.name(“State”)). send keys (“Telangana”);
obj. find element (By.name(“Pin code”)). send keys (” 500038″);
//select country, which is drop down list
select s= new
select ( obj. find element (By.name(“Country”));
- select by visible text (“INDIA”);
// fill remaining fields
obj. find element (By. name(“email”)). send keys (” Kalamstudents”);
obj. find element (By. name (“Password”)). send keys (“scoobydo”);
obj. find element(By .name (“Confirm password “)). Click ( );
Thread . sleep (5000);
//close site
obj. close ( );
Note 1 :
Thread is not selenium class. It is a static class in java. This class can provide sleep ( ) method to create waiting state in execution. This method will take time to wait in millisecond as long integer (synchronize ).
Thread. sleep (time in milliseconds);
the above concept is also called as “Synchronization”.
Note 2 :
Web driver class object is allowing us to automate a text box or edit box shown below .
Note 3 :
Web driver class obj is allowing us to automate a checkbox like shown bellow.
obj. find element (By.name(” Passport”)).Click( );
Note 4 :
Web driver class object is allowing us to automate radio button like shown below.
obj. find element (By. name (“Male”)). Click ( );
Note 5 :
web driver class object is allowing us to automate hyperlink like shown below.
obj. find element (By .link text (“baba”)). Click ( );
obj. find element (By. partial link text (“ba”)). Click ( );
Note 6 :
web driver class object is allowing as to automate image like shown below.
obj. find element (By .name (“XXX”)). click ( );
Note 7 :
web driver class object is allowing us to automate push button like shown below.
obj. find element (By.name(“User id”)). send keys (“xyz”);
obj. find element (By. name (“Password”)). send keys (“Scooby”);
obj. find element (By .name (“Ok”)). Click ( );
Note 8 :
web driver class object can join with select class object to automate drop-down list ( combo box ) when those drop- down lists developed in < select> tag in Html.
Select S = new select ( obj. find element (By.name(” Country”)));
S.select by visible text (“INDIA”)
S.select by index (82) ; index for INDIA
S.select by value (92); value for INDIA
To get index of required item in dropdown list we need to count items by start with zero. To get value of an item in dropdown list , we need to apply firebug on that element to get source code which can show value of items.
In this article we have seen Examples of Scripts for Automation – Selenium Training . In the next article will see the Script for Gmail registration automation.