Our new report is live! State of AI for Software Developers Report 2024 Read it now→

Our new report is live! State of AI for Software Developers Report 2024 Read it now→

Selenium Interview Questions for Experienced Developers

March 18, 2022

What are the most frequently asked advanced Selenium interview questions ?

Selenium is an open-source (free) automated testing framework for validating web applications across multiple browsers and platforms. Developers can write Selenium Test Scripts in various programming languages, including Java, C#, Python, and others.

Jason Huggins invented Selenium in 2004. He worked at ThoughtWorks as an engineer on a web application requiring frequent testing. After seeing that repeated Manual Testing of his apps became increasingly inefficient, he designed a JavaScript program to control the browser’s behavior automatically. The name of this application is “JavaScriptTestRunner”. It released the open-source JavaScriptRunner, and later, we called it Selenium Core after seeing the promise of this concept in helping automate other online applications.

This blog post contains Selenium interview questions and answers to help experienced programmers prepare for their interviews.

Create a top-notch Selenium resume and find Selenium developer roles worldwide without compromising privacy.

selenium interview questions - signup

10 Advanced Selenium Interview Questions and Answers

1. How do you use implicit and explicit waits in Selenium?

According to the official Selenium documentation, not mixing both Implicit and Explicit Waits is a better option. If we mix the two, we can cause unpredictable wait times.
For example, setting an implicit wait of 10 seconds and an explicit wait of 15 seconds can cause a timeout after 20 seconds. This can cause unpredictable waiting times.

The code needs only one implicit wait, which remains constant throughout the driver object instance.
On the other hand, an explicit wait is wherever required in the code and invoked at execution time. Explicit wait, if implemented in code, overwrites implicit wait.

selenium interview questions

2. How do you send ALT/SHIFT/CONTROL key in Selenium WebDriver?

With Selenium webdriver we can send keyboard shortcut ALT SHIFT z(hotkey). Keys class helps to do this. We will use the Keys.chord method and pass Keys.ALT, Keys.SHIFT and z as parameters to this method.

The entire value from the Keys.chord method is obtained as a String. Then it’s sent as a parameter to the sendKeys method.

3. How to take screenshots in Selenium WebDriver?

A Screenshot in Selenium Web driver is for error analysis. Selenium webdriver can automatically take a screenshot during execution. However, if users need to capture a screenshot on their own, they must use the TakeScreenshot method, which tells WebDrive to take the screenshot and store it in Selenium.

You can take a screenshot using the TakeScreenshot function. You can save this screenshot using the getScreenshotAs() method.

Taking Screenshots in Selenium is a 3-Step process
1) Convert the webdriver object to TakeScreenshot
2) Call getScreenshotAs method to create image file
3) Copy the File to the Desired Location

selenium interview questions

4. How do you set the size of browser window using Selenium?

You can adjust the size of the browser window in the following ways:

getSize() method: This method doesn’t take any input parameters, and its return type is an instance of a class named Dimension. This class contains the width and height of the target WebElement. Below code needs to get the width and height of the search box: WebElement searchBox = driver.

JavaScript executor: JavascriptExecutor is an environment to simplify the use of Selenium JavascriptExecutor, allowing WebDriver to interact with HTML elements inside the browser.

5. What are MaxInstances and MaxSession Properties in Selenium Grid?

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

On the other hand, MaxSession is a set of browsers that can run in parallel on a remote machine, regardless of type and version.

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

6. How to input text in the text box without calling the sendKeys() using Selenium?

With the help of the JavaScript Executor, text can be entered into the text box without the sendKeys method.
Selenium executes JavaScript commands with the help of the executeScript method.

The JavaScript command to be executed is passed to the method as a parameter. To enter text, first define the input box with the Document.getElementById JavaScript method, then apply the value method to it.

7. How do you find broken links using Selenium Webdriver?

Broken links are inaccessible links or URLs. They may or may not be down due to some server errors.

A URL will always have a state with 2xx valid. There are different HTTP status codes with different purposes. The HTTP status for an invalid request is 4xx and 5xx.

You will need to do the following steps to check for broken links.

Collect all the links on the web page by the <a> tag.
Send HTTP request for connection and read HTTP response code.
Find out if the connection is valid or broken based on the HTTP response code.
Repeat this for all captured links.

8. What is the use of Robot class?

The Robot Class in Selenium provides automated testing for applications of the Java platform.
Developers prefer it for generating native login events for test automation, self-running demos, and other applications where you need control.

WebDriver cannot handle OS popups, so Robot class was introduced in Java 1.3.

9. What are some of the Robot Class internal methods?

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

keyPress(): This method will press the arrow key of the keyboard.
mouseMove(): This moves the mouse pointer to specific X and Y coordinates.
mousePress(): This method will press the right click of the mouse.
mouseRelease(): This method will release the right click of the mouse.
keyRelease(): This method will release the down arrow key of the keyboard.

10. How do you connect the database through Selenium?

In Selenium, the JDBC driver connects to a database.

To connect to database in Selenium, follow these steps:

  • Load the required JDBC driver class.
    Class.forName(“net.sourceforge.jtds.jdbc.Driver”);
  • Establish a connection to the database:
    Connection con = DriverManager.getConnection(“DataBaseURL”, “userName”, “password”);
  • Connection URL:
    jdbc:sqlserver://ipAddress:portNumber/dbName
  • 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()) {
    System.out.println(resSet.getString(required_column_name));}
  • Closing the database connection. con.close();
selenium interview questions - signup

If you’re feeling prepared for your Selenium interview, it’s time to meet a job opportunity that’s right for you!

TalentGrid is a platform used by software developers who are actively looking for jobs, allowing them to share their preferences and salary expectations with employers around the world.

By creating your TalentGrid developer profile, you’ll have an opportunity to be matched with global positions!

Ready to complete your free profile and find your next role in tech? Sign up today!

Recent Posts

Go to Top