Top Selenium Interview Questions for SDET

Beknazar
8 min readDec 20, 2023

--

Hi there! I put together the top Selenium and some general test automation interview questions for SDET or Test Automation roles.

Please consider taking my Udemy course Interview Preparation for SDET(Java) if you prefer video sessions with more detailed explanations.

General Questions:

How do you determine which test to automate?

  • The test should be part of the regression suite because we automate it to reduce the manual effort for the regression suite.
  • The test should be automatable. The tools we use can automate this test and the test is repeatable.

What do you do when your automated suite is failed?

First, we check if the automation test failed because of the automation script itself or if it failed because of unexpected behavior from the application. Usually, it is easy to look into screenshots or videos if frameworks produce them.

If it is an issue with the script itself, I open the ticket with the details of the failure and in the next sprint cycle, we will fix it. Meanwhile, I will test this test manually and attach the details in the overall test automation run reports.

If it is an issue with the application, then I will reproduce it manually and open a defect ticket.

How do you do a regression test on your project?

A big portion of our regression suite is automated for our project and we execute them in Jenkins before each release. The rest of the not automated test, we execute manually.

What percentage of your regression is automated?

We automated around 60% of our regression suite.

Selenium Questions:

What are the advantages and disadvantages of Selenium?

The advantages:

  • Cross-browser Compatibility: Selenium supports multiple browsers, making it a great fit for testing web applications.
  • Open Source: Selenium is free to use and has a large community of users and developers.
  • Extensive Ecosystem: Selenium offers a wide range of tools and frameworks for different testing needs.

The disadvantages:

  • It is not suitable for testing desktop applications.
  • Selenium primarily focuses on web applications and has limited support for mobile app testing.

What is a Document Object Model (DOM) in the UI?

DOM is an object representation of HTML. We can say it is an object model of the HTML document. The HTML and DOM are in sync.

What kind of locators do you know in Selenium?

  • ID
  • Name
  • Class name
  • Xpath
  • CSS
  • Link text and partial link text
  • Tag name

Which locator do you prefer?

I prefer ID and name when they are unique. The next preferable locator is CSS, then if I need to write more complex locators I will work with xpath.

What’s the difference between absolute and relative paths?

The absolute path starts at the root of the HTML and uses the single slash (/) to navigate to the target element.

The relative path can start from any place in the HTML and uses double (//) to navigate to the target element. The relative path is more widely used than the absolute path.

What is the difference between xpath and CSS locators?

The main differences:

  • CSS is faster than xpath.
  • Xpath has more features to build complex paths. It has many useful methods. For example: finding via text, text contains, and text equals.
  • Xpath can traverse the DOM in any direction (upwards, downwards) whereas CSS only downwards.

How do you handle dynamic elements?

  • By using xpath’s contains method by finding a static part of the element.
  • Another way is by finding a static element and building my path from that element to my dynamic element.

What’s the difference between implicit and explicit waits?

  • The implicit wait is a global wait. We need to declare it once at the beginning of the execution. It gets applied to all element locators.
  • We use explicit wait in special cases where we need to wait for a special event to occur. Like: element appearing, element disappearing, etc.

What’s the default wait time between checks in the implicit wait?

It is 0.5 sec.

What’s the main disadvantage of implicit wait?

Since it applies to all element locators, it can slow down overall execution time.

What’s fluent wait in Selenium?

  • It is used to wait for certain events.
  • We can configure polling time.
  • We can configure specific exceptions to be ignored.

What’s the difference between findElement and findElements?

  • findElement method returns a single WebElement. It throws a NoSuchElement exception if the element doesn’t exist.
  • findElements method returns the list of WebElements. It returns an empty list if element/s doesn’t exist.

How do you check if an element exists in the DOM?

  • We can try to locate this element and catch an exception if it fails.
  • We use the findElements method to check if an element is in the DOM. If it returns an empty list then the element doesn’t exist in the DOM.

How do you work with multiple windows in Selenium?

  • Each window has a unique windowHandle (sort of ID of the window).
  • We can read these window handles via Selenium and switch between windows.

Example of switching to the latest window and switching back to the original:

How do you work with iFrames in Selenium?

  • Switch to iFrame first by using switchTo() method.
  • You can switch by index, id, and name.
  • Once you complete your task in the iFrame, you can switch back by using default content.

Example:

How do you work with UI dropdown in Selenium?

When the dropdown is based on a select tag then we can use the Select class to work with it. Otherwise, we work similarly as with any other element in Selenium.

Example:

How do you work with popups in Selenium?

  • We use Alert class to work with alert-based popups in Selenium.
  • We can accept, dismiss, getText, and sendKeys using the Alert class.
  • We need to switchTo alert. However, we need to wait for an alert to be present (explicit wait).

Example:

How do you type text in an input box in Selenium?

We do it by using the sendKeys(text) method.

Example:

How do you upload files in Selenium?

We do it by using the sendKeys(filePath) method as well.

Example:

What does the Actions class do in Selenium?

Actions class provides an ability to handle keyboard events, mouse events, and special actions. Some common actions:

  • Drag and drop.
  • Mouse hover over.
  • Double click.
  • Right-click.

What is the Page Object Model (POM)?

POM is a design pattern in Selenium that creates an object repository for storing web elements. In POM, we have each web page of an application as a class. Each class will contain only corresponding web page elements and methods to work with this page. It helps reduce code duplication.

How do you deal with stale element exceptions in Selenium?

  • The stale element exception occurs when the connection with WebElement and the actual UI element is not up to date. For example, the script located an element on one page and then navigated to another page which led to the loss of the connection. Then when you are back to the original page to work with the element, you might get a stale element exception.
  • The best approach to this problem is to retry to locate the element with a minor wait.

What is Remote WebDriver?

Selenium lets you automate browsers on remote computers with Selenium Grid running on them. The computer that executes the code is referred to as the client computer, and the computer with the browser and driver is referred to as the remote computer or sometimes as an end node. To direct Selenium tests to the remote computer, you need to use a Remote WebDriver class and pass the URL including the grid port on that machine.

What is Selenium Grid?

Selenium Grid allows the execution of WebDriver scripts on remote machines by routing commands sent by the client to remote browser instances.

Grid aims to:

  • Provide an easy way to run tests in parallel on multiple machines.
  • Allow testing on different browser versions.
  • Enable cross-platform testing.

What is SauceLabs and BrowserStack?

Sauce Labs and BrowserStack are both cloud-based platforms that provide infrastructure for testing web and mobile applications across different browsers, operating systems, and devices.

  • They offer tools and services that enable developers and QA teams to test their applications in different environments to ensure compatibility and functionality.
  • They provide a platform that offers a cloud-based Selenium grid for automated testing of web and mobile applications.

Thank you for your attention. Please consider taking my online courses:

--

--

Beknazar
Beknazar

No responses yet