Top 10 interview questions for Selenium

Sachin Joshi
3 min readApr 27, 2022

--

  1. What is Page Object Model(POM) ?

In every webpage of the application is should have a corresponding page class which should be responsible for locating the web elements and performing actions on them.

Page Object Model(POM) is a design pattern which helps to create object repositories of the web elements.

POM improves code reusability and readability. which means Multiple test cases can be run on the object repository.

2. What is difference between findElement() & findElements() ?

findElement() is used to access any single element on the web page. It returns the object of the first matching element of the specified locator.

findElements() is used to find all the elements in the current web page matching the specified locator value. All the matching elements would be fetched and stored in the list of Web elements.

Examples:

WebElement element = driver.findElement(By.id(example));

List <WebElement> elementList = driver.findElements(By.id(example));

*** findElement() will return as WebElement whereas findElements() will return List of WebElements

3. How to perform scrolling operation in selenium, can you give an example ?

we can use scrollBy() method to scroll the webpage

General syntax:

executeScript(“window.scrollBy(x-axis,y-axis)”);

At first, we need to create a JavaScript object

JavascriptExecutor is = (JavascriptExecutor) driver;

Then, Launch the AUT(application under test)

driver.get(“https://www.google.com”);

Use below command to Scroll down to the desired location in webpage

js.executeScript(“window.scrollBy(0,1000)”);

4. Why we cannot automate captcha using Selenium ?

The whole concept of Captcha is to ensure that bots and automated programs don’t access to sensitive information. which is why, Selenium cannot automate it.

5. How will you handle window based popup’s using Selenium ?

We need to use third-party tools like AutoIT, Robot, etc which can be integrated with Selenium to handle pop-ups and other Windows-based features as Windows-based features are not natively supported by Selenium.

6. How many exceptions we can expect in Selenium ?

  • NoSuchElementException: no element could be located by the locator provided.
  • ElementNotVisibleException: an element is present in the DOM but is not visible.
  • NoAlertPresentException: try to switch to an alert box but the targetted alert is not displayed.
  • NoSuchFrameException: try to switch to a frame but the targetted frame is not present.
  • NoSuchWindowException: try to switch to a window but the targetted window is not present.
  • UnexpectedAlertPresentException: unexpected alert blocks the normal interaction of the driver.
  • TimeoutException: command execution gets a timeout.
  • InvalidElementStateException: state of an element is not appropriate for the desired action.
  • NoSuchAttributeException: trying to fetch an attribute’s value but the attribute is not correct.
  • WebDriverException: some issue with the driver instance preventing it from getting launched.

7. How will you use file upload operation ?

sendKeys.

Using element.sendKeys(“path of file”) on the webElement of input tag and type file i.e. the elements should be like –
<input type=”file” name=”fileUpload”>

Robot API.

AutoIT API.

8. How to execute JavaScript in Selenium ?

JavaScript code can be executed in Selenium using JavaScriptExecuter.

9. What are some advantages of Selenium grid ?

Advantages of Selenium grid are,

  1. Allows running test cases in parallel and allows us to save test execution time.
  2. Multi-browser testing is possible using the Selenium grid.
  3. Also, we can do multi-platform testing by configuring nodes having different operating systems.

10. What is Selenium locator and what are different types of locators present in Selenium ?

Locator is an address to identify web elements uniquely identify within a web page.

There are different types of locators present in Selenium to identify web elements uniquely and accurately like:

  • ID
  • ClassName
  • Name
  • TagName
  • LinkText
  • PartialLinkText
  • Xpath
  • CSS Selector
  • DOM.

11. What are different Types of waits in Selenium ?

There are 3 different types of waits in Selenium,

  • Implicit wait
  • Explicit wait
  • Fluent wait

you may read more details on each wait type in my article which is dedicated to waits only click here to navigate.

hit the follow button for more topics on Java, RestAssured, GraphQL, Selenium, JavaScript, JUnit, Jenkins, GitHub Actions, WebUI, SOAP & VBScripts

https://medium.com/@sachinjoshi12687

Also, DM me if you want me to add new topic of your choice urgently.

--

--

Sachin Joshi
Sachin Joshi

Written by Sachin Joshi

follow me for more topics on Java, RestAssured, GraphQL, Selenium, JavaScript, JUnit, Jenkins, GitHub Actions, WebUI, SOAP & VBScripts