Home » Top Selenium Interview Questions – 2023

Top Selenium Interview Questions – 2023

Selenium Automation Interview Questions - 2022 Updated

Important Selenium automation interview questions and answers including simple Selenium Java interview questions for freshers and experienced candidates to crack the interview.

1. What are MaxInstances Properties in Selenium Grid?

MaxInstances is defined as the number of browser instances of the same version of the browser that can run on the remote machine.

for eg.

-browser browserName=InternetExplorer,version=11,maxInstances=3,platform=WINDOWS

-browser browserName=Firefox,version=12,maxInstances=2,platform=WINDOWS

This will allow running 5 instances (3 instances of IE and 2 instances of Firefox) at the same time on a remote machine.

2. What are MaxSession Properties in Selenium Grid?

MaxSession is defined as a number of browsers, independent of the type & version, that can run in parallel on the remote machine.

MaxSession overrides the MaxInstances settings and hence can restrict the number of browser instances that can run in parallel.

For eg.

If maxSession=1 then only a single browser will run on a remote machine. If maxSession=2 then any two browsers can run at a time irrespective of MaxInstances that we defined. It can be either 2 Internet Explorer or 2 Firefox or 1 Internet Explorer and 1 Firefox.

browser browserName=firefox,maxInstances=5,maxSession=2

3. How can we handle Web-based Pop-ups or Alerts in Selenium?

Web-based alerts or popups are handled by switching to the alert window and calling Selenium WebDriver Alert API methods.
Below methods are called for various actions:

  • dismiss(): To click on the Cancel button.
  • accept(): To Click on the OK button.
  • getText(): To get the text which is present on the Alert.
  • sendKeys(): To enter the text into the alert box

4. What happens if you mix both Threads. Sleep and WebDriver Waits in a Selenium Script?

Thread.sleep() method is used to pause the execution of the script for a specified time in milliseconds

If WebDriver waits are used along with Thread.sleep() method, then webdriver will hold the execution for a specified time (as mentioned in Thread.sleep()) and then will follow another wait. If we mix both the waits, then the test execution time will increase.

5. How can you use the Recovery Scenario in Selenium WebDriver?

Recovery Scenarios are used by using the “Try Catch” block within Selenium WebDriver Java tests.try{

6. What is Robot Class in Selenium and what are its advantages?

Robot Class is used to control the keyboard or mouse to interact with Operating System windows like download pop-ups, alerts, print pop-ups, etc, or native OS applications like Notepad, Calculator, Skype, etc. while doing browser automation.

The various advantages of Robot Class are:

  • It simulates Mouse and Keyboard events.
  • It helps in the upload/download of files while using Selenium webdriver.
  • It gets easily integrated with the current automation framework (keyword-driven, data-driven, or hybrid framework).

7. What are various Robot Class internal methods and explain their usage.

Some of the Robot Class Internal methods and their usage are as follows:

  • keyPress(): eg. : robot.keyPress(KeyEvent.VK_Down) : This method will press down the arrow key of keyboard.
  • mouseMove(): eg. robot.mouseMove(point.getX(), point.getY()) : This will move the mouse pointer to specific X and Y coordinates.
  • mousePress(): eg. robot.mousePress(InputEvent.BUTTON_DOWN_MASK): This method will press the right click of mouse.
  • mouseRelease(): eg. robot.mouseRelease(InputEvent.BUTTON_DOWN_MASK): This method will release the right click of mouse.
  • keyRelease(): eg. robot.keyRelease(KeyEvent.VK_DOWN): This method will release the down arrow key of keyboard.

8. How to Upload a file in Selenium WebDriver?

We can upload a file in Selenium WebDriver using the AutoIT script. Follow the following steps for uploading a file with the AutoIT script:

  • Download and Install the “AutoIT”.
  • Open Eclipse and write code through Selenium WebDriver on clicking on the “Upload File” button.
  • Ensure FileUpload.exe is generated after compilation in the location where AutoIT is installed. This FileUpload.exe already contains the file(say, devLabsAlliance.docx) to be uploaded and this is pre-configured through the AutoIT editor.
  • After clicking of Upload button, the AutoIT script needs to be called, and then the control is immediately transferred to AutoIT in order to upload a file, and then the control is sent back to Selenium.
    Syntax for calling AutoIT script:

9. How to run Selenium test from Command Line in Selenium WebDriver?

For doing this, we need to install TestNG and need to set the classpath.

Follow the below steps:

10. How to connect a database in Selenium?

To connect a database in Selenium, we use the JDBC driver while using the Java Programming language.

Follow the below steps to connect the database in Selenium:

  • Load the required JDBC driver class.
  • Establish a connection to the database:
    Connection con = DriverManager.getConnection(“DataBaseURL”, “userName”, “password”);
  • Connection URL:
  • Execute SQL Queries:
    Statement sqlStatement = con.createStatement();
    String sqlQuery = “SELECT * FROM table_name WHERE condition”
    ResultSet resSet = sqlStatement.executeQuery(sqlQuery);
  • Fetching data from resultSet:
    while (resSet.next()) {
  • Closing the database connection. con.close();

Explore more interview questions: Selenium Interview Questions for Beginners and Experienced Candidates

Explore related Workshops:
Certified SDET Professional
Certified SDET Advanced
Certified SDET Professional – Python
Certified Selenium with C# Professional