http://www.technicalpage.net/search/label/SQL

Selenium Interview Questions and Answers Part 3:

To watch in YouTube: Click Here

 

1.      What are implicit wait and explicit wait in Selenium ?

Implicit wait :

It is a wait in selenium which once created, applies to all the elements. That is why it is also called global wait. It waits until the given time limit before throwing exception, "No Such Element Exception". If the element is found before the time limit then it moves on ignoring the remaining time of the given time limit. The default wait time is 0 second.

An example of explicit wait is as below, in this example, the wait time limit is 10 seconds :

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Explicit wait:

This wait does not apply to all the elements unlike implicit wait. This wait waits for the condition such as “presence of element located by”, “visibility of element located by”. This also waits until the given time limit for the condition before throwing exception. If the condition is met before the time limit then it moves on ignoring the remaining time of the given time limit.

WebDriverWait wait = new WebDriverWait(driver,10);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath")));

 

2.      What is difference between navigate and  get  ?

“get” is used for opening a webpage in a browser.

“navigate” is used for multiple purposes.

Examples:

driver.get(“https://www.technicalpage.net”); => this will open the webpage.

 

driver.navigate.to(“https://www.technicalpage.net”); => this will open the webpage.

driver.navigate.refresh(); => this will refresh the current web page.

driver.navigate.forward(); => this will take you to the next page which comes when you click forward icon on the browser window.

driver.navigate.back();=> this will take you to the next page which comes when you click back icon on the browser window.

 

3.      How you handle multiple tabs in Selenium ?

To get the current tab we use driver.getWindowHandle()

 

But for more than one tabs, we use,

Driver.getWindowHandles() command. This will return a set of string elements as below:

Set<String> tabs = driver.getWindowHandles();

 

Then we use “iterator” to switch to each of the tabs as below:

Iterator<String> it = tabs.iterator();

String tab1 = it.next();

String tab2 = it.next();

driver.switchTo().window(tab1);

driver.switchTo().window(tab2);

 

and at the end of the testing , we close all the tabs by using below command:

driver.quit();

 

 

4.      What is the difference between the interface and abstract class ?

ToTo watch in Youtube: What are the difference between an Interface and an Abstract Class?

Interface:

1.      The objects(methods, variables etc) inside interface are by default “public” and only “public” visibility(access modifier) can be used.

2.      The visibility should not change when the interface is implemented by any class.

3.      The methods in interface should be abstract only.

4.      The implementing class should define all the undefined methods inside the interface.  

5.      An interface can extend another interface(one or many) or a class can implement an interface(one or many).

6.      The variable inside interface are by default public static and final so the variable must be assigned a value. 

7.      Multiple inheritance is possible in the interface.

8.      Interface uses “Interface” keyword to declare the interface.

9.      An interface can not have a constructor

10.   An interface can not create object ,ie, can not instantiate.

 

Abstract Class:

1.      The objects(methods, variables etc) inside Abstract Class can be “public”, “private”, protected” or “default”.

2.      The visibility might change when an abstract class is inherited by another class.

3.      The methods inside abstract class can be abstract or non-abstract.

4.      The inheriting(child) class does not need to implement all the abstract methods of the parent class and if it does not implement all the abstract methods, then this child class also becomes an abstract class.

5.      An abstract class can implement interfaces(one or many) or can extend another class(abstract or non-abstract).

6.      The variable inside an abstract class can be static, non-static, public or other visibility, final or non-final and does not need the variable value to be assigned.

7.      Multiple inheritance is possible in an abstract class when it implements multiple interfaces. But a class(abstract or non-abstract) can not extend multiple classes. So, multiple inheritance will not be possible if we try to extend more than one class.

8.      Abstract class uses “abstract” keyword to declare the abstract class.

9.      An abstract  class can have a constructor.

10.   An abstract class can not create object ,ie, can not instantiate

 

5.      What is method overloading and method overriding?

Method Overloading:

When a class has more than one methods with same name but different parameters(either different types of parameters or different order of parameters), this is called method over loading.

findSales();

findSales(int i);

findSales(int i, String s);

findSales(String s, int i);

findSales(double i);

 

Method overriding:

When two or more classes having parent/child relationship, are having method with same name and same parameterization( or no parameterization), is called method overriding .  In such situation, when the method is called, the child method gets precedence. 

Example:

Parent class

public class Employee {

      

       public void methodA()

       {

              System.out.println("This is method in parent class.");

              }     

}

Child class

public class Dept extends Employee {

 

       public void methodA()

       {

              System.out.println("This is method in child class.");

              }

}

 

Running above codes:

public class Run {

       public static void main(String[] args) {       

              Dept obj = new Dept();

              obj.methodA();

             }

}

 

 

Output:

This is method in child class.

 

 

6.      What is inheritance ?

Inheritance is a process to establish a parent-child relationship between the classes. In this the child class ( also called sub class) uses the features(methods, properties) of parent class (also called super class). The child class uses the word “extends” to use the features  of the parent class. Hence we can use the code, method of the parent class.

 

Types of Inheritance:

Single level

Multilevel

Multiple

Hybrid

Hierarchical

 

7. How you get a page title in Selenium ?

Driver.getTitle();

Or

To store the title in a variable

String pageTitle = driver.getTitle();

 

8. What is data driven framework ?

It is a framework in which the data and the test code will be separate so that change in data will not affect the code and vice versa. 

We keep the data in Excel, CSV, XML, Database etc. And we read the data whenever required by the code from the data sources.

 

9. What is the difference between the single forward slash(“/” ) and double forward slash (“//” ) ?

Single forward slash is for absolute xpath, ie, if single slash is used in the xpath , than it is called absolute xpath. In this the xpath starts from the root node. So, the xpath becomes long and complicate. And this xpath will have more possibility of breaking as it is long and if any of the node changed in the middle, the xpath does not work.

Double forward slash is for relative xpath. In this the xpath starts from the node/point from where an unique xpath is possible. This xpath is short and there is less possibility of such xpath breaking. So, relative xpath will be more reliable than absolute xpath.

 

Example:


 

Absolute xpath: /html/body/div/div[2]/div/div/div/div/div[2]/form/table/tbody/tr[2]/td/input[@id='email']

Relative xpath: //input[@id='email']

 

 

10. What is the difference between findElement() and findElements() ?

FindElement() will locate/find the first element on the current page. It returns a single web element.

WebElement webelement = driver.findElement(By.xpath(""));

 

findElements() will find all the matching element on the current page. It returns a list of web elements.

      List<WebElement> webelements = driver.findElements(By.xpath(""));


No comments:

Post a Comment