Simple if condition:-
Syntax:-
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 conditions.
Syntax:-
if(i==0)
{ s.o.p (i);
}
Else if(i==1)
{
s.o.p(i);
}
Else if(i==2)
{
s.o.p(i);
else
. .
For loop condition:-
For(int i=0;i<10;i++)
{
s.o.p(i);
}
Ajax control:-
Ajax 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.
Interested in mastering Selenium Training? Enroll now for FREE demo 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:-
the string contains multiple values, if we are planning to check one value in the string, we need to use the split method.
the string contains multiple one, two, three, four. check that “three” is available in the string. if available print it.
Split:-
we 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.
ARRAYS:-
It is a class data type where we can store multiple values with similar data types.
Syntax:-
String str[];
Int i[];
Object o[];
String comparison commands:-
we can compare two strings with the 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(“ ,”);
System.out.print/n(s.length);
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”);
Thread.sleep(1000);
String str;
Str=driver.findelement(by.xpath(“// …….”)).gettext();
System .out.println(str);
String s[ ]=str split(“n”);
System.out.println(s.length);
For(int i=0;i<s.length;i++)
{
//system.out.print(s(i));
If(s[i].executeignore(“selenium testorial”))
{
System.out.println(s[i]);
Driver.findelement(by.id(“gbqfq”)).clear();
Driver.find element(by.id(“gbqfq”)).sendkeys(s[i]);
}
}
}
Learn more about Selenium Interview Questions in this blog post.
Assignment:-
GO to spicejet.com click on leaving from the field and check that Hyderabad, Bangalore &Chennai are available or not.
** How to handle web tables?[how to take the data from o table]
we can identify the base by using the location lib XPath or id e.t.c
After finding the element takes the data[text]by using the command get a text()
the get text () return type in a 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 the 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;
@test(enabled=false)
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);
}
@test
Public void verify spicejet tooltip() {
Driver.get(http://spicejet.com);
String str=driver.find element(by.xpath(“………..”)).get attribute();
System.out.println(str);
}
Note:-
Whenever we are planning to take multiple elements from the application we have to use “find elements” .the return type of this command is a list.
List:-
It is from the collection in java where it is an advanced version of the array. In array, we can store multiple values where it is dependent to the declaration.
Ex:- string str [ ]=new string [s];
Public void f() {
Driver.get(http://spicejet.com);
List<web element>str=new select(driver.find element(by.id(“….”).get options();
System.out.println(str.size());
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());
}
}
Assignments:-
** Go to the register page of mail.in.com in
1)print all dropdown id’s
2)print all textboxes id’s
** write a program to print the text box's, button id’s &dropdown id’s in the login page, register 1®ister 2 pages 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 checkbox 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.
check that either username 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 the result file.
Public void verify user name() {
Driver.get(http://mail.in.com);
If(driver.find element(by.id(“f-id”)).is displayed())
{
System.out.println(“available”);
} else { system.out.println(“not available”);
}
If(selenium.is element present(“f-id”))
{
System.out.println(“available”);
} else {
System.out.println(“not available”);
}
Assert:-
It works the same as if condition. if the 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
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.