Professional Documents
Culture Documents
Answer: Explicit Wait will make the WebDriver wait for a specific web element for the
specified time. i.e. Using Explicit Wait, we can make the WebDriver wait for web element 'a' for
5 seconds and another web element 'b' for 10 seconds.
Where as Implicit Wait will make the WebDriver wait for all web elements for the same
specified time. Its generally not set for one or two web elements, instead it is once set will be
applicable for all elements. i.e. Unlike Explicit Wait, Implicit Wait once set will be applicable to
all the web elements and hence the specified wait time will be applicable for all the web
elements.
Answer: First of all WebDriver is an Interface and there are different classes which implement
this Interface in Selenium. The Classes which implement the WebDriver interface in Selenium
are FirefoxDriver, ChromeDriver, InternetExplorerDriver, OperaDriver, SafariDriver,
RemoteWebDriver, EdgeDriver and EventFiringWebDriver Classes.
Answer: Tool Tip is a text that will be displayed when we hover our mouse cursor over the text
or web element on any web page. Selenium WebDriver can read the tool tip text using
getAttribute() method. Click here to read how Selenium WebDriver uses getAttribute() method
for reading a tool tip from a web page.
4. What are the different WebDriver exceptions, you have faced while working with
Selenium Projects ?
Answer: Exception is a problem which occurs during the execution of the program and there by
stops the program from further execution. Similarly, while running the Selenium programs,
different types of Exceptions related to WebDriver may arise. The list of WebDriver related
Exceptions that may commonly arise during Selenium programs execution are:
NoSuchElementException, ElementNotVisibleException, NoSuchFrameException,
NoAlertPresentException, NoSuchWindowException, SessionNotFoundException and
StaleElementReferenceException. Click here to find out more on these WebDriver exceptions.
5. Can Selenium automate Desktop Applications ?
Examples: Web Applications like Facebook.com, Gmail.com etc can be automated by Selenium.
Where as the Desktop Applications like Paint, Skype, MS Office etc. cannot be automated by
Selenium.
Selenium got released into the market in three different versions so far and hence Selenium 3 is
the latest version.
Answer: Firebug is a firefox add-on which helps us in locating HTML code for the inspected
GUI elements on the web pages.
Answer: Selenium is one of the components / tools of Selenium and is a Record & Playback
tool.
Selenium is one of the components / tools of Selenium and is a Record & Playback tool.
11. What is the disadvantage of using Selenium IDE ?
Answer: Its not suitable for automating the complex applications, as the maintenance of
automated tests is more. i.e. If any functionality changes on the application, the automation
engineer has to re-record all the automated tests which got affected with this change again in
Selenium IDE
Answer: id, name, class name, link text, css selectors , xpath expressions and DOM are the
different types of locators which we use in Selenium for locating the GUI elements on the web
pages.
id, name, class name, link text, css selectors , xpath expressions and DOM are the different types
of locators which we use in Selenium for locating the GUI elements on the web pages.
14. What is the difference between Absolute XPath and Relative XPath Expressions ?
Hence because of simple changes in the applications functionality, the complete path in absolute
XPath may change. Since Relative XPath is the direct path, its path won't change with the simple
changes in the application.
15. What is the disadvantage of Absolute XPath and why is Relative XPath recommended
over it ?
Answer: For simple changes on the application like moving the button from one place on the
page to other place, the absolute XPath expression changes. As Relative XPath expressions won't
change with these simple UI changes on the pages, hence Relative XPath is recommended over
Absolute XPath.
16. What is the concept that makes XPath Expressions powerful out of all the
locators ?
Answer: XPath AXES is the concept which makes the XPath Expressions powerful out of all the
locators. i.e. By using XPath AXES we can traverse both forward and backwards in the HTML
code of the web pages.
17. Why CSS Selectors have higher priority over XPath Expressions ?
Answer: The below are two reasons why CSS Selectors are preferred over XPath Expressions:
When compared to XPath Expressions, CSS Selectors locate the UI elements faster.
Selenium may not be able to locate few UI elements using XPath Expressions, while
executing the Automation scripts on Internet Explorer Browser.
18. What is the name of the Add-on which can automatically generate the XPath
Expressions and CSS Selectors ?
Answer: Firepath is the Add-on which can auto generate the XPath Expressions and CSS
Selectors, just by inspecting the GUI elements on the web pages.
19. Write a Java Program to print the even numbers between 1 and 100 using for loop ?
Answer: The below for loop can print the even numbers between 1 to 100:
for(int i=1;i<=100;i++) {
if(i%2==0) {
System.out.println(i);
20. Write a Java Program to find the sum of first 100 numbers using for loop ?
Answer: The below for loop can find the sum of first 100 numbers:
int sum = 0;
for(int i=1;i<=100;i++) {
sum = sum + i;
21. Write a for loop which prints numbers from 1 to 100. But if the number is divisible by
5, then it should print 'divisible by 5 followed by that number' ?
for(int i=1;i<=100;i++) {
if(i%5==0) {
System.out.println("Divisible by 5 : "+i);
}else {
System.out.println(i);
}
22. Does Java support multiple inheritance ?
Answer: The answer is No and Yes. i.e. No in case of Classes and Yes in case of Interfaces.
In case of Classes, a single class cannot inherit multiple classes due to the ambiguity problem.
Lets say there are three Classes i.e. ClassA, ClassB and ClassC. Assume that ClassA and ClassB
have a method having same name say mOne() . In this case, if ClassC extends both ClassA and
ClassC, then there is an ambiguity of inheriting mOne() from either ClassA or ClassB. i.e. Java
cannot decide whether the mOne() can be inherited from ClassA or ClassB.
In case of Interfaces, a single class can inherit multiple interfaces as there is no ambiguity
problem.
Lets say there are two interfaces i.e. InterfaceA, InterfaceB and a class ClassC. Though
InterfaceA and InterfaceB have a method with same name say mOne(), ClassC can still inherit
multiple interfaces, as mOne() method is not implemented in any of the interfaces.
23. What is the parent or base class of all the classes in Java ?
Answer: All the classes in Java are children or grand children of Object Class.
24. What is the difference between instance variables and local variables in Java ?
Answer: Variables declared inside the methods are known as local variables, where as the
variables which are declared directly inside the class but outside the methods are known as
Instance variables.
Answer: No. Java uses primitive data types, hence it is not a 100% or pure Object Oriented
Programming language.
26. What is the difference between Primitive and Non-Primitive Data types in Java ?
Answer: Predefined or default data types in Java are known as Primitive Data types.
Examples for Primitive Data types are : byte, short, int, long, float, double, char and boolean
Programmer defined data types in Java are known as Non-Primitive Data types. objects can be
created for non-primitive data types.
Examples for Non-Primitive Data types are : Strings, Arrays and Classes.
Answer: In Java Strings are by default immutable (i.e. once created they cannot be changed).
For example: If you assign a value to the String say "Arun Motoori" as shown below:
And, in the next statement, I will change the value of the String to other value say "Arun Kumar"
as shown below:
After performing the above two steps, though it looks like the value has been updated. But in real
a new object will be created to store new value "Arun Kumar" and the old object storing "Arun
Motoori" is not deleted. i.e. Instead of updating or changing the value stored in old object, a new
object will be created for every new value assigned to the same variable of String.
So in Strings, on assigning a value to the variable, a new object will be created to store the value
and the value stored in the object cannot be changed or mutated. Hence Strings are immutable in
Java.
28. What is the difference between String and StringBuffer classes in Java ?
Answer: Strings in Java are immutable (i.e. cannot be changed once created), where as
StringBuffer is mutable.
Answer: The below program accesses all the elements of a two dimensional array using
for loop:
for(int i=0;i<a.length;i++) {
for(int j=0;j<a[i].length;j++) {
System.out.print(a[i][j]+" ");
}
System.out.println();
}
30. How to assign different types of values say integer, character, String, decimal
and boolean into the same array ?
Answer: By creating the arrays as Object Class type, we can assign different types of
values say integer, character, String, decimal and boolean into the same array.
Answer: Arrays are fixed in size. i.e. After creating an Arrays, we cannot change its size at
later point of the program.
32. Practical Assignment : Go to Java 8 API page over Web and find the String predefined
class and its predefined methods say equals(), substring(), length(), trim() etc. .
Answer: The below are the steps to find the String predefined class and its
predefined methdos in Java 8 API:
Search "Java 8 API" in google search
Click on the https://docs.oracle.com/javase/8/docs/api/ from search results
Search for 'String' predefined class in the displayed Java 8 API Library page
And in the page the page of 'String' predefined class page, scroll down a bit and
find its predefined methods.
Answer: The below are few differences between constructors and methods in Java:
When this Overloading technique is applied to methods is known as method overloading and
when applied to constructors is known as constructor overloading.
Answer: Packages in Java are used to group / organize the related Classes, Interfaces and
other Files.
40. What is the keyword used by a Java Class to inherit the Properties say
Variables and methods of another Class ?
Answer: No,
Overriding can be implemented only for methods and cannot be
implemented for Constructors.
Reason: As the name of the constructors needs to be same as the name of the Classes,
Overriding is not applicable for constructors.
Answer: Modifiers
in Java can be categorized into two types i.e. Access modifiers and
Non-Access modifiers.
Different Access modifiers we have in Java are - public, private, protected and
default
Different Non-Access modifiers we have in Java are - static, final and abstract
Answer: Both default and protected access modifiers specified properties act as public
to all the Classes inside the same package.
But coming to the Classes outside the package, default and protected properties act as
private.
The difference between default and protected is that, protected specified properties
can be inherited outside the package, where as default specified properties cannot be
inherited outside the package.
46. What is the difference between static variables and instance variables in Java ?
Answer: static variables belong to the class memory, hence needs to be called using the
Class name. Where as instance variables belong to the object memory, hence needs to be
called using object reference.
47. What are the differences between static methods and non-static methods in
Java ?
Answer: The below are the differences between static methods and non-static methods
in Java:
static methods belong to class memory, hence needs to be called using the
Class name. Where as non-static methods belong to object memory, hence
needs to be called using object reference.
static methods can only access static variables and static methods. Where as
non-static methods can access both static and non-static variables and methods.
Answer: Thevariables and methods will be have as below on providing them with final
non-access modifier:
Answer: abstract classes contains abstract and non-abstract methods, where as all the
methods inside the interfaces are by default abstract type.
The difference between default and protected is that, protected specified properties
can be inherited outside the package, where as default specified properties cannot be
inherited outside the package.
53. Assignment: Create a sample text file having ten lines of text and read the text
from the file using file handling mechanism with the help of while loop ?
Answer: Please find the below program for reading the text form the file using while loop:
String str;
while((str=br.readLine())!=null){
System.out.println(str);
br.close();
Answer: Arrays are fixed in size, where as collections overcome this disadvantage as they
are growable in size.
55. What is the difference between ArrayList and HashSet in Java ?
Answer: ArrayList stores the objects in an organized manner using index values, where as
HashSet stores the objects in a random order and don't have index values.
56. What is the relation ship between Iterator interface and iterator() method in
Java ?
Answer: iterator() method is the predefined method of Collection interface and the return
type of iterator() method is Iterator interface.
57. What are the predefined methods of HashMap, which are used for adding the
value and retrieving the values in Java ?
Answer: HashMap uses put() method for storing key value pairs, and uses get(key) for
retrieving the values.
1
12
123
1234
12345
123456
1234567
for(int i=1;i<=7;i++) {
for(int j=1;j<=i;j++) {
System.out.print(j+" ");
}
System.out.println();
}
60. Write a program in Java to create an integer array and print the elements of
the array in reverse ?
int[] a = {9,3,6,8,4,7};
for(int i=a.length-1;i>=0;i--) {
System.out.print(a[i]+" ");
}
String[] a = {"One","Two","Three","Four"};
for(int i=0;i<a.length;i++) {
System.out.println(a[i]);
i++;
}
62. Write a program in Java to find the greatest number in an integer array ?
int[] a = {9,3,6,4,8,5};
int temp = a[0];
for(int i=0;i<a.length;i++) {
if(temp<a[i]) {
temp = a[i];
}
}
63. Write a program in Java to find the least number in an integer array ?
int[] a = {9,3,6,4,8,5};
int temp = a[0];
for(int i=0;i<a.length;i++) {
if(temp>a[i]) {
temp = a[i];
}
}
System.out.println("The least value in the array is "+temp);
Examples:
Java compiler accepts 'public' keyword, but complier error will be displayed on
providing 'Public' keyword.
Java compiler accepts 'System' keyword, but complier error will be displayed on
using 'system' keyword with print statements
Example: In the below code, Demo is the class name and class is the keyword which
is defining / creating it.
Answer: The below are few examples which give compiler errors in Java:
When we don't end any Java statement with ; symbol
Java is case sensitive, hence we get compiler errors when we provide wrong
cases
When starting brace '{' count, don't match the ending brace count '}'
70. What are the different things required for storing data in Java ?
Answer: The below are the different things required for storing data in Java programs:
Data types
Variables
Literals
Assignment operator =
72. What are the different data types in Java and what is their purpose ?
Answer: The below are the different data types in Java:
byte
short
int
long
float
double
boolean
char
Purpose: On declaring a variable with int data type, we can store integer values into the
variables and on declaring a variable with boolean data type, we can store true/false into
the variables. Hence data types define the type of values we can store into their defined
variables.
The purpose of the break; statement is to come out of the statements based on
some condition.
The purpose of the continue statement is to skip the current iteration of a loop based on
some condition and continue with the next iteration.
Answer: Yes, the same method can be called any number of times in Java.
79. What is the keyword to be used in Java while declaring methods, when the
method don't have anything to return ?
Answer: void is the keyword , we have to use when the method don't return any value
to its calling method.
81. What is the predefined variable of Arrays, which can be used to find the size of
the arrays ?
Answer: 'length' is a predefined variables of Arrays, which is used find the size of the
arrays.
82. Provide an example for using for loop with single dimensional arrays ?
Answer: Please find the below example:
int[] a = {5,3,9};
for(int i=0;i<a.length;i++) {
System.out.println(a[i]);
}
83. Provide an example for using for-each loop with single dimensional arrays ?
Answer: Please find the below example:
int[] a = {5,3,9};
for(int temp:a) {
System.out.println(temp);
}
84. Write a Java Program to print the even numbers between 1 and 100 using for
loop ?
Answer: The below for loop can print the even numbers between 1 to 100:
for(int i=1;i<=100;i++) {
if(i%2==0) {
System.out.println(i);
}
85. Write a Java Program to find the sum of first 100 numbers using for loop ?
Answer: The below for loop can find the sum of first 100 numbers:
int sum = 0;
for(int i=1;i<=100;i++) {
sum = sum + i;
86. Write a for loop which prints numbers from 1 to 100. But if the number is
divisible by 5, then it should print 'divisible by 5 followed by that number' ?
for(int i=1;i<=100;i++) {
if(i%5==0) {
System.out.println("Divisible by 5 : "+i);
}else {
System.out.println(i);
Answer: Both driver.get() and driver.navigate().to() do exactly the same. They both take
you to the page of the provided URL. driver.get() is easier than driver.navigate().to(), as it
takes very less time to type. In addition to this, driver.navigate() also has the capability to
navigate back, navigate forward() and refresh the page using back(), forward() and
refresh().