Skip to main content
Displaying 1 - 10 of 83

Have you ever used Method Overriding in your Selenium Java Framework?

Overrided Method in Selenium are:

WebDriver driver = new FirefoxDriver(); 
Actions act = new Actions(driver);	 
TouchActions tapAction = new TouchActions(driver).singleTap(driver.findElement(By.id("testid"))); 

Overriding in Selenium is best depicted by "get" and "navigate" methods for different browser.

Have you ever used Method Overloading in your Selenium Java Framework?

Method Overloading: Method overloading is a feature of Java in which a class has more than one method of the same name and their parameters are different.

Overloaded method in Selenium are:

  1. frame(string), frame(int), frame(WebElement)
  2. findElement("<All type of locator e.g. id , xpath , cssClass>").
  3. wait(), wait(timeout), wait(timout,nanos)

Example: Select and Deselect List

public class MyList
{ 
    Select list; 

    public Listbox(Select list) 
    {
        this.list = list; 
    } 
    
    public void select(int i) 
    { 
        this.list.selectByIndex(i); 
    } 

    public void select(String text) 
    { 
        this.list.selectByVisibleText(text); 
    }

   // Same way you can do it for deselect and other methods
}

Mention the need of session handling while working with Selenium.

While working with Selenium, we need session handling. This is because, during test execution, Selenium WebDriver has to interact with the browser all the time to execute the given commands.

It is also possible that, before the current execution completes, someone else starts the execution of another script in the same machine and in the same type of browser. So to avoid such a situation, we need session handling.

What are the different methods to refresh a web page in Selenium WebDriver?

There are multiple ways, 5 of them are mentioned below:

1. Using driver.navigate command:

driver.navigate().refresh();

2. Using driver.getCurrentUrl() with driver.get() command:

driver.get(driver.getCurrentUrl()); 

3. Using driver.getCurrentUrl() with driver.navigate() command:

driver.navigate().to(driver.getCurrentUrl());  

4. Pressing an F5 key on any textbox using the sendKeys command:

driver.findElement(By textboxLocator).sendKeys(Keys.F5);

5. Passing ascii value of the F5 key, i.e., "\uE035" using the sendKeys command:

driver.findElement(By textboxLocator).sendKeys("\uE035"); 

What is difference between get() and navigate().to() method?

Below are the difference between driver.get() and driver.navigate().to() method: 

  • Browser History: driver.get(url) does not maintain the browser history and cookies where as driver.navigate.to(url) maintains browser history and cookies.
  • Page Load: driver.get(url) wait till the page fully loaded where as driver.navigate.to(url) does not wait till the page fully loaded.
  • Forward/Backward: We can not move forward/backward between the pages with driver.get() but we can navigate between the pages back, forward and refresh with driver.navigate().
  • Speed: navigate() is faster than get() because navigate() does not wait for the page to load fully or completely.
  • Execution: get() method execute next line of code once the page is completely loaded but  navigate() method does not wait for loading of page, it executes once the url hit into searche-box.

There are Variations of Navigate to() method:

void to(java.lang.String url): Load a new web page in the current browser window. This is done using an HTTP GET operation, and the method will block until the load is complete. This will follow redirects issued either by the server or as a meta-redirect from within the returned HTML. Should a meta-redirect "rest" for any duration of time, it is best to wait until this timeout is over, since should the underlying page change whilst your test is executing the results of future calls against this interface will be against the freshly loaded page.

void to(java.net.URL url): Overloaded version of to(String) that makes it easy to pass in a URL.

How do you generate report in Selenium?

There are multiple ways to generate reports in Selenium:

Extent Report: Extent Reports is a customizable HTML report which can be integrated into Selenium WebDriver using JUnit and TestNG frameworks. 

ReportNG: ReportNG is a simple plug-in for the TestNG unit-testing framework to generate HTML reports as a replacement for the default TestNG HTML reports. You can also customize html report with the help of TestNG listeners.

TestNG: The TestNG will generate the default report. When you execute testng.xml file, and refresh the project. You will get test-output folder in that folder. 

JUnit: JUnit is another useful framework that can add the ability to generate reports in Selenium. It provides the JUnit <TestWatcher> class to introduce reporting ability.

The JUnit’s TestWatcher class has the <failed()> and <succeeded()> methods which you can override. The JVM would call them automatically whenever it found a pass or failure.

Subscribe to Selenium with Java Interview Questions

About

Elix is a premium wordpress theme for portfolio, freelancer, design agencies and a wide range of other design institutions.