71 UnAnswered Critical Selenium interview questions

In this tutorial of selenium interview questions, we will cover all the critical Selenium interview questions questions along with advanced Selenium Automation framework interview questions .This tutorial is divided into three segments :

Selenium Framework Interview Questions

Advance selenium interview questions

Intermediate selenium interview questions

NOTE : The focus of this Selenium interview Questions and Answers tutorial is to discuss most critical and complex questionnaire as you might already be aware of the basic questionnaires on .

Initially we will start with Advance Selenium Framework interview questions and answers and then move forward Critical/Advanced selenium interview questions and answers and then lastly we finish this tutorial with intermediate levels so that you can prepare well.

Selenium Interview Questions
Selenium Interview Questions

Selenium Framework Interview Questions

Advance Selenium Interview Questions

Intermediate selenium interview questions

Selenium Framework Interview Questions : 

How many popular types of Selenium framework are there?

There are four different types of Selenium framework are there, which are : 

How many different approaches are there to design the Page Object Model framework?

What is Page factory in selenium ?

PageFactory is a class from Selenium library from a package called as org.openqa.selenium.support which helps to design the Page Object Design pattern in the Page Object Model framework, which has few implementations such as :

What is the key design difference between Classic Page Object Model and Customized Page Object Model?

So each webpage should have one interface to store locators and 1 class for the page level web operations and their respect assertions.

What is the design principle of the Page Object Model Framework?

The Design principle of the Page Object Model framework is based on principles or concepts, which are : 

So, All the page actions(different operations of the web page functionality)reside on the respective Page classes.

Mention the key differences among Page Object Model and the Hybrid Page Object Model?

The difference between Page Object Model and Hybrid Page Object Model is that the Hybrid Page Object Model is based on Page Object Model framework Design along with the extensive features of the Data-Driven Framework and supports a wide variety of the Data Operations Utilities such as below : 

What is the language Parser used in the Cucumber -BDD framework?

The language parser used in the Cucumber -BDD framework is Gherkin.

What is the Gherkin language?

Gherkin is DSL (Domain Specific Language) and English like language, which is very much readable and understandable (i.e., give(), when(),then(), etc.)

What do you mean by given() in Gherkin?

 Given () method states that some situation or scenario is given or stated.

 What do you mean by when() in Gherkin?

When () means when you perform some operations.

What do you mean by then() in Gherkin?

then() is used as assertions after the operations are performed by given().when() .

What CI tool do you use as part of the framework?

We use Jenkins (majorly) as an open-source CI tool.

What build tool do you use as part of the framework?

We use build tools such as Maven/Gradle/ant (it was previously used).

What is the key difference between maven and Gradle?

Gradle is the advanced version of what maven perform, and along with that, we can create tasks as well (like the feature that was available in ANT ), so we can consider on a high level : 

Gradle =>> Maven +Ant 

As part of Selenium C#, we use Gallio as a build tool. 

What’s the Unit Test framework that we use as part of the Selenium Automation framework?

We majorly use TestNG/JUnit(JUnit is less used nowadays) as part of the unit test framework while building the Automation framework with Selenium. 

As part of the Selenium C# framework, We use NUnit/MbUnit as a unit test framework.

What approach can be taken into consideration while designing the Reporting tools as part of the Selenium framework?

There is various reporting approach we could take while designing the framework :

Apart from these open-source reporting tools integration, we can also opt for some advanced reporting features or dashboard to build with the below technologies and tools :

How do you use ELK to build the reporting dashboard with Selenium Framework :

There is a basic base design principle which is being used to design the Automation dashboard, which are : 

How do you build an HTML customized report?

You can make use of different listeners and reporters interfaces provided by TestNg to record the events and their respective data sets and create HTML by using those data sets and the HTML tags in the report utils.

What are the challenges that you have faced while developing a framework?

There are different challenges you can mention as per your experience gives while developing the framework, for example : 

Mention which all Selenium components you have used in your Selenium Framework?

You can mention depending on your framework.

What is the flow of your Automation framework?

You can mention the flow of execution of your framework depending on your Framework flow and the tools that you have used; below is an example you can mention :

CI(Jenkins) → Build Tools (Maven/Gradle) → Unit Test Framework (TestNg) → TestNg.xml ->> TestClasses → BaseTest(Every Test Class extends Base class as baseTest where the @beforeClass /@BeforeSuite @afterClass etc exits )–>TestMethods → PageClasses→ Page Methods→ WebUtilities(reusable class for the WebAction utilities )–>> Reporting Utils 

What do you understand by Data-Driven framework, and where do we use a Data driven framework?

A Data-Driven framework is basically a framework that is driven by Data. Having said that, in which the application or the type of the application where the Same Test cases or scenarios is executed several times with the different data sets or the source or Data is very vast like in the case where we need to interact a variety of Data sources there we use Data-driven framework. 

The different Data Source can be : 

How to explain the selenium automation framework in an interview?

 There are different approaches you can take to explain the selenium automation framework in an interview; the best possible approach could be the modular approach, which is to break down the explanation into different separate modules, such as :

Let’s Discuss in Detail : 

Type of the Framework and Key and unique features of the Framework :

You need to mention the type of the framework such as Hybrid Framework, page object model framework, hybrid Page Object Model framework, etc. 

You need to mention the unique features of the framework, such as for example :

Tools and Technologies used in Selenium framework :

You can mention the tools and technologies used while developing the framework, such as :

The flow of the execution of the Selenium Framework :

You can mention the flow of the framework execution, i.e., how do you trigger the test suites and how it flows to the test cases/methods and till the Framework Utils such as webutils, data utils, etc. You can refer to the above question where we discussed how to explain the flow of the execution of the Selenium framework.

Different Critical Scenarios handled by your framework :

In this module, you can discuss the critical features that have been automated as part of your application automation with your framework. There can many use cases or features that you can mention here, such as : 

How to design logging scenarios in the Selenium framework?

You can use log4j for logging, or you can use real-time logging and debugging dashboard implementation with Graylog, which basically uses ElasticSearch in the backend for real-time logging and debugging details.

What are the design patterns you have used while designing the framework?

You can use different Design patterns as per the need and design of the Automation framework, such as :

Critical or Advance Selenium Interview Questions :

How many ways can you run your automation script parallelly?

There are multiple ways and approaches through which you can run your test scripts parallelly, such as : 

Maven :

Using surefire plugin : 

<forkCount>5</forkCount>

 <reuseForks>true</reuseForks>

Here fork count represents the number of parallel threads count.

Gradle : 

tasks.withType(Test) {
        maxParallelForks = Runtime.runtime.availableProcessors()
    }

What is the difference between setSpeed() and sleep() methods?

setSpeed() method in Selenium basically sets the speed of the execution of each and every action/command. 

So let’s say if you setSpeed(“2000”), then every line of execution will be delayed by 2000 milliseconds. 

On the other hand, Thread.sleep() will introduce a 3000 milliseconds delay (it will suspend the thread for the specific operation ). 

Hence sleep() is applied to 1 operation; on the other hand, setSpeed() introduces the delay for each and every operation and thus setting the speed of the execution.  

How to verify the presence of a ScrollBar with Selenium? 

To verify horizontal scroll bar in webpage with Selenium, we use Javascriptexecutor in the below manner : 

JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
Boolean presenceOfHorizontalScroll = (Boolean) javascriptExecutor.executeScript("return document.documentElement.scrollWidth>document.documentElement.clientWidth;");

To verify the vertical scroll bar in WebPage using Selenium webdriver also we need to use Javascriptexecutor

JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
Boolean presenceOfVerticalScroll  = (Boolean) javascriptExecutor.executeScript("return document.documentElement.scrollHeight>document.documentElement.clientHeight;");

Write the code to handle any hidden Web elements in selenium webdriver?

WebElement element=driver.findElement(By.id("id_of_Element"));
JavascriptExecutor jsExecutor = (JavascriptExecutor)driver;
jsExecutor.executeScript("arguments[0].click();", element);

Mention different approaches to handle a window based pop up using Selenium webdriver?

You can use the below approaches to handle Window based application such as window Pop up : 

What is the parent interface of WebDriver?

SearchContext

Mention the key differences between POI and JXL Jars?

POI supports Conditional formatting, rich text formatting, or xlsx format, but on the other hand, JXL does not support any of these features.

POI library is maintained and updated compared to JXL.

How do you handle your network latencies using Selenium?

We can use the following to handle network latency using in Selenium : 

Driver.manage.pageloadingtime

What are the approaches you would take to handle Ajax content testing with Selenium WebDriver?

AJAX is basically Asynchronous Javascript And XML. All the communication of the AJAX-based Application is based on asynchronous calls, 

which allow any event to be performed without refreshing the webpage. Each operation can be performed independently from other Events.

What are the challenges while working with AJAX calls in Selenium WebDriver?

To work with the AJAX application, you may need to use waits for the above-mentioned use cases : 

What’s the approach to work with Proxy in Selenium Webdriver?

There are two different Approaches you can handle proxy in Selenium Webdriver : 

Proxy proxy=new Proxy();
proxy.setHttpProxy("localhost:8889");
DesiredCapabilities capabilities=new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver=new FirefoxDriver(capabilities);

Mention the ways to achieve synchronization in WebDriver?

We can handle synchronization in Selenium webdriver by using different wait mechanism : 

Mention the key differences between TestNg @BeforeTest and @BeforeMethod ? 

In TestNg @BeforeTest and @BeoreMethod has different aspects, are:

List the different types of WebDriver APIs present in Selenium?

How many ways you can achieve headless execution with Selenium?

We can use the below drivers to achieve headless automation with Selenium: 

What is Fluent Wait In Selenium WebDriver?

With FluentWait, you can set a maximum amount of time(let’s say 3 minutes ) to wait to meet a specific condition, and during that time, you will continuously poll or check with a certain frequency (very small unit of time, let’s say 3 secs )to check.

If the condition is met, then it will return true, and if not, it will throw an “ElementNotVisibleException” exception.

The syntax of fluentwait in Selenium is :

Wait fluentWait = new FluentWait(driver).withTimeout(100, TimeUnit.SECONDS)
  .pollingevery(2, TimeUnit.SECONDS)
  .ignoring(ElementNotVisibleException.class);

Tell us some Selenium exceptions that you have encountered while working with` Selenium WebDriver?

How do you delete cookies in Selenium?

The command to delete the cookies in Selenium is : 

driver.manage().deleteAllCookies();

Explain the approach that how do you read the javascript variable in selenium webdriver?

We need to use JavascriptExecutor to be able to do so. 

JavascriptExecutor jsExecutor = (JavascriptExecutor) webdriver;
String jsVariable = (String.valueOf(jsExecutor.executeScript("return document.title")));

How To Perform Zoom In And Zoom Out Browser operation In Selenium?

We can perform zoom in and zoom out operation in Selenium by using two different approaches, such as : 

Zoom in using Robot class in selenium

Robot robotInstance = new Robot();
//Zoom in

robotInstance.keyPress(KeyEvent.VK_CONTROL);
robotInstance.keyPress(KeyEvent.VK_ADD);
robotInstance.keyRelease(KeyEvent.VK_ADD);
robotInstance.keyRelease(KeyEvent.VK_CONTROL);

Zoom out using Robot class in selenium


Robot robotInstance = new Robot();
robotInstance.keyPress(KeyEvent.VK_CONTROL);
robotInstance.keyPress(KeyEvent.VK_SUBTRACT);
robotInstance.keyRelease(KeyEvent.VK_SUBTRACT);
robotInstance.keyRelease(KeyEvent.VK_CONTROL);

Zoom in using Keys class in selenium

driver.findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL,Keys.ADD));

Zoom out using Robot class in selenium

driver.findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL,Keys.SUBTRACT));

How to clear a field in selenium without using a clear() method?

We can clear any field without using the clear() method in the below approach : 

We can use the Keys class in Selenium to achieve the same : 

WebElement element = driver.findElement(By.id("id_of_Element"));
element.sendKeys(Keys.chord(Keys.CONTROL, "a"));
element.sendKeys(Keys.DELETE);

How to rerun the failed test cases in selenium?

We can rerun the failed test cases in Selenium in the below two approaches :

With auto-generated TestNG-failed.xml :

After the test execution (ran from testng.xml), TestNG automatically generates TestNG-failed.xml; you can rerun the same XML to run the failed tests ONLY.

By implementing IRetryAnalyzer interface from testNg :

By implementing the interface IRetryAnalyzer we can automatically rerun the failed test cases with TestNg :


If you implement the IRetryAnalyzer you can auto rerun  failed test with TestNg :

public class Retry implements IRetryAnalyzer {
   int counter = 1;
   int retryMaxLimit = 3;
   public boolean retry(ITestResult result) {
       if (counter < retryMaxLimit) {
           counter++;
           return true;
       }
       return false;
   }
}

How to Highlight Element in Selenium WebDriver?

We can use JavascriptExecutor to set the color of the Webelement by mentioning the element.


WebElement element = driver.findElement(By.xpath("id_of_the_element"));
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
jsExecutor.executeScript("arguments[0].setAttribute('style', 'background: red; border: 2px solid red;');", element);

How to double click in selenium?

We can use the Actions class in Selenium to perform the DoubleClick operations in the below manner. The below method takes an argument on which you have to perform DoubleClick.

public void doubleClick(By locator) {
\t\ttry {
\t\t\tWebElement element = driver.findElement(locator);
\t\t\tActions actions = new Actions(driver).doubleClick(element);
\t\t\tBASE_LOGGER.info("Performed the double Click on the Element  : " + locator);
\t\t} catch (StaleElementReferenceException e) {
\t\t\tBASE_LOGGER.error("Element is not attached to the page document " + e.getCause().getMessage());
\t\t} catch (NoSuchElementException e) {
\t\t\tBASE_LOGGER.error("Element " + locator + " was not found in DOM " + e.getCause().getMessage());
\t\t} catch (Exception e) {
\t\t\tBASE_LOGGER.error("Element " + locator + " was not clickable " + e.getCause().getMessage());
\t\t}
\t}

How to scroll in selenium?

We need to use Javascript to perform the scrolling, and the below method provides an advanced approach to scroll into element till the element is visible, which is scroll into view : 

public void scrollIntoView(By locator) {

  try {
     JavascriptExecutor executor = (JavascriptExecutor) driver;
     WebElement element = driver.findElement(locator);
     executor.executeScript("arguments[0].scrollIntoView(true);", element);
     BASE_LOGGER
           .info("scrollIntoView operation has been performed for the locator : " + String.valueOf(element));
  } catch (Exception e) {
     String exceptionData = e.getCause().getMessage();
     BASE_LOGGER.error("Error encountered i.e : " + exceptionData
           + " while performing scrollIntoView on the element : " + locator);

  }

}

How to get all links on the page in selenium?

We can use By.tagName(“a”) to fetch all the links that are available on the page as link refers to the tag called as a; the method goes in the below manner : 

public List<WebElement> getAllLinks() {

  try {
     List<WebElement> allLinks = driver.findElements(By.tagName("a"));
     int numberOfLinks = allLinks.size();
     BASE_LOGGER.info("Number of Links in the Current Page is : " + numberOfLinks);
     BASE_LOGGER.info("GetAllLinks operation has been performed for the Current Page : ");
     return allLinks;
  } catch (Exception e) {
     String exceptionData = e.getCause().getMessage();
     BASE_LOGGER.error("Error encountered i.e : " + exceptionData
           + " while performing GetAllLinks for the Current Page :");
     return null;
  }

}

How to find the number of iframes on a page in Selenium?

We can use the below method to find the number of iframes in a page in Selenium :

public int numberOfIframesInPage() {
  try {
     JavascriptExecutor exe = (JavascriptExecutor) driver;
     Integer numberOfIFrames = Integer.parseInt(exe.executeScript("return window.length").toString());
     BASE_LOGGER.info("Number of IFrames in the current Window are : " + numberOfIFrames);
     return numberOfIFrames;

  } catch (Exception e) {
     BASE_LOGGER
           .error("Exception occurred in Finding numberOfIframesInPage with : " + e.getCause().getMessage());
     return 0;
  }

}

How to switch to default frame in selenium webdriver?

We can use switchTo().defaultContent() method to switch to default frame in Selenium Webdriver: 

public void switchToDefaultFrame() {
  try {
     driver.switchTo().defaultContent();
     BASE_LOGGER.info("Switched to Default Content ");
  } catch (Exception e) {
     BASE_LOGGER.error("Exception Occurred while switching to default Content ");
  }
}

How to handle tabs in selenium?

We can use a List to store all the tabs available and use driver.getWindowHandles() to store the tabs, and once after this, we can handle tabs one by one in the below approach, such as : 

public void switchToTab(int indexOfTab) {

  try {

     ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
     driver.switchTo().window(tabs.get(indexOfTab));
     BASE_LOGGER.info("Successfully switched to tab with tab index as : " + indexOfTab);
  } catch (Exception e) {
     String exceptionData = e.getCause().getMessage();
     BASE_LOGGER.error(
           "Unable to Switch to Tab for :" + indexOfTab + " i.e failed with exception as : " + exceptionData);

  }



}

Intermediate selenium interview questions

Is WebDriver a class or an interface?

Webdriver is an interface where all the driver classes such as ChromeDriver, FirefoxDriver create an object and have reference to the Webdriver interface’s reference.

Which one is faster, XPath, or CSS?

CSS is faster than XPath. 

Why CSS is faster than XPath?

Every browser engine is different, and hence parsing strategy and engine implementation are different through the written XPath. That is why parsing XPath becomes inconsistent at times; for example, IE does not have its own engine implementation to parse XPATH; hence Selenium injects its own native XPath engine to parse XPATH in IE. 

What is heightened privileged browsers?

When the browsers are opened up with some predefined settings (instance with special privileged mode )such as with certain Profiles or Certificates, then it’s called heightened privileged browsers sessions. 

We can launch a browser with Selenium with Profiling or set certificates for the same purposes.

What is headless browser Selenium and how we perform headless browser testing?

  A headless browser is a simulation program for the browser where we don’t have a UI, but we still can run Application under test in invisible mode 

 and perform the desired web operation in the background.

 We use HeadLess browser drivers such as HTMLUNIT driver or phantomJS Driver to perform headless browser testing.

Selenium vs. puppeteer ? 

There are several differences between Selenium and puppeteer (which is a new tool compared to Selenium and developed by Google Chrome DEV)

We will discuss here the comparison between Selenium VS Puppeteer in different aspects : 

HardAssert vs SoftAssert ?

Both the assertion approaches are from TestNg, and each of them has its respective pros and cons

 When you are under the circumstances where you need to have an assertion that’s obvious, i.e., without that step, the remaining steps of the script do not make sense to be executed, then you can put Hard Assert there.

 How to set the window size in selenium?

We can create an object of Dimension class and pass that object to setSize() method : 

Dimension dimension = new Dimension(480,700);
driver.manage().window().setSize(dimension);

What is the version control system you use while working with Selenium?

You can mention whatever VCS you use, such as Github, SVN, etc.

How to clone a git repo?

We can clone the git repo by using :

Git clone repo

How to pull the Git repo code?

Git pull remoteRepoURL branchName

How to push the code to git repo?

Git push remoteURL branchName

How to set the Remote? 

git remote add ProvideARemoteName remoetURL

How to verify the available remotes?

Git remote -v 

How to check which remote URL you currently are in? 

git config --get remote.origin.url

How can you integrate your framework with Jenkins?

As part of the Selenium Automation framework, we are using build tools(such as Maven/Gradle), and we can create a Jenkins Job and connect the Maven/Gradle by providing the configuration with VCS (i.e., Github, etc.)

What are the disadvantages of Sikuli?

How to perform database testing using selenium?

We can perform database testing using selenium in the below modular approach : 

Here is below code snippet for the above steps : 

Selenium Database connection Setup with JAVA JDBC and creates a DB statement : 

   static Connection connection = null;
   private static Statement statement;
   public static String DataBase_URL = "DB_URL";
   public static String DataBase_USER = "DB_UserName";
   public static String DataBase_PASSWORD = "DB_password";



   /* This method Creates the connection with Java JDBC and return it to the Test method to use along with statement 
   */
@BeforeTest
   public void setUp() throws Exception {
       try{

           String dbClass = "com.mysql.cj.jdbc.Driver";
           Class.forName(dbClass).newInstance();
           Connection con = DriverManager.getConnection(DataBase_URL, DataBase_USER, DataBase_PASSWORD);
           statement = con.createStatement();
       }
       catch (Exception e)
       {
           e.getCause().getMessage().toString();

       }


   }

Use the statement to query the DB with SQL : 

@Test
public void test() {
   try{
       String queryData = "select * from TableName";

       ResultSet res = statement.executeQuery(queryData);
       while (res.next())
       {
           System.out.print(res.getString(1));
           System.out.print(" " + res.getString(2));
       }
   }
   catch(Exception e)
   {
       e.getMessage();
   }
}

Closing the Data Connection : 

This step is very important; otherwise, we may end up creating multiple database connections without closing them after the usage, which may cause several issues. 

Here is the code snippet for the same : 

@AfterTest
public void tearDown() throws Exception {

   if (connection != null) {
       connection.close();
   }
}

How to verify the background color and color of a WebElement using Selenium? 

We need to use a method called getCssValue(“color”) for retrieving the colour of a webelement and getCssValue(“background-color”) to pull the background colour of a webelement.

Here is the code snippet : 

String colour  = driver.findElement(By.xpath("XPATH_of_the_Element")).getCssValue("color");

String backgroundColour = driver.findElement(By.xpath("XPATH_of_the_Element")).getCssValue("background-color");

How to verify the font-size of a WebElement using Selenium webdriver? 

We can use the the method called getCssValue(“font-size”)

String fontSize  = driver.findElement(By.xpath("XPATH_of_the_Element")).getCssValue("font-size");

How to verify the font type of a webelement in Selenium Webdriver? 

String fontSize = driver.findElement(By.xpath("XPATH_of_the_Element")).getCssValue("font-type");

How to get tooltip text in selenium?

Getting tooltip text of a WebElement is nothing but getting the title attribute of the Webelement in the below manner : 

public String getToolTipData(By locator){

   WebElement element=driver.findElement(locator);
   return element.getAttribute("title");
}

What is StaleElementException? 

Stale Element means that when a Web element is no longer attached with the DOM/WebPage which was present previously. In that case, Selenium throws a staleelementexception.

This may happen for several multiple reasons like due to AJAX or JavaScript calls which changes the state

of the element makes it unavailable/detached from DOM.  

Conclusion : With these we are done with the Sets of Critical Selenium interview questions covering Selenium Framework interview questions , Read through here to get in depth concepts of Selenium to understand the architecture of Selenium.

Leave a Comment