• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

Conditional statements in Selenium

Conditional statements in Selenium in Detail

Simple if condition:-



{  statement ;

} else { statement


Ex:-     if( int i==0)


s.o.p(“is pass”);


Else {

s.o.p(“is not pass”);


Nested if condition:- It is for multiple condition.



{  s.o.p (i);


Else if(i==1)




Else if(i==2)




. .

For loop condition:-

For(int i=0;i<10;i++)




Ajax control:-

2Ajax means dynamic when we enter any value in the field based on the input the field will display the list of suggested values ,those fields are nothing but ajax control.

Aspired to become a Selenium Developer ? Explore the post to discover the know-hows on Selenium Training.

** write a program to type selenium in Google textbox check that selenium historical is displaying in the suggested list or not .If it is displaying then type the value ,if not print a message not available.


String splits:-

2string contains multiple values ,if we are planning to check one value in the string we need to use the split method.

2string contains multiple one, two, three, four. check that “three” is available in the string .if available print it.


2we can split the string by using some regular expression[value].The value which we are using to split will be eliminated from the string .The remaining values will be stored in an array.


2It is a class data type where we can store multiple values with similar data types.


String  str[];

Int i[];

Object o[];

String comparison commands :-

2we can compare two strings with below commands.

1) Equals:-it looks for the exact match and it is case sensitive

2) Equals ignore case :- It also looks for the exact match but it is not case sensitive.

String str =” ten,nine,six,seven,one,two,three,four”;

String [ ] s=str.split(“ ,”);


For(int i==0;i<s.length;i++)


If(s[i].executigmore code(“throws”)) }

 Ajax control program:-

Public void f() throws exception {

Driver .get(http://google.co.in);

Driver.find element(by.id(“gbqfq”)).sendkeys(“selenium”);


String str;

Str=driver.findelement(by.xpath(“// …….”)).gettext();

System .out.println(str);

String  s[ ]=str split(“\n”);


For(int i=0;i<s.length;i++)



If(s[i].executeignore(“selenium testorial”))




Driver.find element(by.id(“gbqfq”)).sendkeys(s[i]);




Learn more about Selenium Interview Questions in this blog post.


2GO to spicejet.com click on leaving from field and check that Hyderabad ,Bangalore &Chennai are available or not.

** How to handle web tables ?[how to take the data from o table]

2we can identify the base by using the location lib xpath or id e.t.c

2After finding the element take the data[text]by using the command get text()

2the get text () return type in string

Information  commands:-

1) we can have the information from the application which is available with in the tag àget attributes()

2) get text():-It is to take the text or label from the application where it will be outside of tag.

3) get option():-we can take all the values from a dropdown.

**write a program to print Google search  Hindi display names and tooltip of google image.

Public class information {

Public web driver driver;


Public void f() {

Driver .get(http://google.co.in);

String str =driver.find element(by.id(“gbqfbq”)).getattribute(“area-lable”);

System.out.println(“button display name is :”+str);

String str =driver .findelement(by.id(“hindi”)).get text();

System .out.println(“link name is :”+str);

String str=driver.find element(by.id(“hpolog”)).get attribute(“title”);

System.out.println(“tool tip is”+str);



Public void verify spicejet tooltip() {


String str=driver.find element(by.xpath(“………..”)).get attribute();



  • Write a program to print all the values from adult dropdown list and check the wheather 5 adult is available in application or not .if available select it.




When ever we are planning to take multiple elements from the application we have to use “find elements” .the return type of this command is list.


It is from collection in java where it is an advance version of array.In array we can store multiple values where it is dependent to declaration.

Ex:- string str [ ]=new string [s];

  • In list we can store multiple values where it is independent of the declaration.
  • Ex:- list<string> str= new arraylist <string>();

Public void f() {


List<web element>str=new select(driver.find element(by.id(“….”).get options();


For(int i==;i<str.size();i++){

//system.out.println(str.get(i).get text());

If(str.get(i).get text().equalsignorecase(“5 adults”))


//system.out.println(str.get(i).get text());

New select (driver.find elements(by.id(“…..”))).select by visible text(str.get(i).get text());




** Go to the register page of mail.in.com in

1)print all dropdown id’s

2)print all text boxes id’s

** write a program to print the text boxid’s, button id’s &dropdown id’s in login page, register 1&register 2 page of mail.in.com.

Validation commands:-

1) Is displayed():- we can validate whether the element is available on the application or not.

2) Is enable():-we can validate either the element is editable or not[either we can perform any action or not]

3) Is selected():- we can validate either the check box or radio button is selected or not.

4) Is element present():- It is from selenium RC it works some as like is displayed() in web driver.

** write a program to click on the radio button one way in the spicejet.com and check that either the application is displaying the return date picture.

2check that either user name is available in mail.in.com by using web driver and selenium RC commands. If it is not available then print the failed result in result file.

Public void verifty user name() {


If(driver.find element(by.id(“f-id”)).is displayed())



} else { system.out.println(“not available”);


If(selenium.is element present(“f-id”))



} else {

System.out.println(“not available”);



It works same as like if condition .if condition will give the result in console only were as the assert will give the result in both console and result file[output file].

Assert.assertResults(driver.find element(by.id(“f-id”)).is displayed().true);

Assert.asserResults(selenium.is elementpresent(“f-id”),true);

For an Indepth knowledge on Selenium, click on below

Review Date
Reviewed Item
Conditional statements in Selenium
Author Rating

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Conditional statements in Selenium"

Leave a Message

Your email address will not be published. Required fields are marked *

Site Disclaimer, Copyright © 2016 - All Rights Reserved.