Selenium interview questions and answers 👇

  1. Selenium Interview Questions


Selenium Interview Questions

What is Selenium Grid?

View answer

Selenium Grid is a smart proxy server that makes it easy to run tests in parallel on multiple machines. This is done by routing commands to remote web browser instances, where one server acts as the hub. This hub routes test commands that are in JSON format to multiple registered Grid nodes.

What are assertions in Selenium?

View answer

In Selenium, Asserts are validations or checkpoints for an application. Assertions state confidently that application behavior is working as expected. One can say that Asserts in Selenium are used to validate the test cases. They help testers understand if tests have passed or failed.

What is a locator in Selenium?

View answer

Locators are the way to identify an HTML element on a web page. Almost all UI automation tools provide the capability to use locators for the identification of HTML elements on a web page.

What is Xpath locator?

View answer

XPath, also known as XML Path, is one of the most commonly used locators in Selenium WebDriver that can help you navigate through the HTML structure of a page. It can be used for HTML and XML documents to locate any element in a web page using HTML DOM structure.

What is Selenese?

View answer

Selenium IDE by default has a language system commonly called Selenese. It is a group of commands used to perform operations on the web. It primarily helps to develop scripts in Selenium IDE. It can verify if an element is present on a screen, alerts, Ajax calls, links etc.

What are Startpoints and Breakpoints in Selenium?

View answer

Start Point tells the Selenium IDE from where to start the execution. Start Point can be used anywhere in the test script, either in the middle of the code or a breakpoint. It also helps in debugging the test script.

Breakpoints are used to tell the Selenium IDE where to pause the test or stop the execution of the test script. This is done to verify that your code is working as expected or not.

What is the same-origin policy?

View answer

Same Origin policy prohibits JavaScript code from accessing elements from a domain that is different from where it was launched. Example, the HTML code in www.google.com uses a JavaScript program “randomScript.js”. The same origin policy will only allow randomScript.js to access pages within google.com such as google.com/mail, google.com/login, or google.com/signup. However, it cannot access pages from different sites such as yahoo.com/search or adaface.com because they belong to different domains.

What are the types of Web locators?

View answer

Selenium supports 8 different types of locators namely id, name, className, tagName, linkText, partialLinkText, CSS selector and xpath. Using id is one of the most reliable and fast methods of element recognition. Usually, the id is always unique on a given web page.

What is the difference between driver.close() and driver.quit()?

View answer

quit() is used to exit the browser, end the session, tabs, pop-ups etc. But the when you driver. close(), only the window that has focus is closed.

How would you retrieve CSS properties of an element?

View answer

getCssValue method in selenium fetches the value of a CSS property of a web element, and we have to pass what property selenium has to fetch.

What is POM?

View answer

Page Object Model, also known as POM, is a design pattern in Selenium that creates an object repository for storing all web elements. It is useful in reducing code duplication and improves test case maintenance.

Is there a way to type in a textbox without using sendKeys()?

View answer

We can input text in the text box without the method sendKeys with the help of the JavaScript Executor. Selenium executes JavaScript commands with the help of the executeScript method.

What are JUnit Annotations?

View answer

A JUnit test annotation is basically meta-data that JUnit provides to determine what action should be performed by a method. It allows developers to organize, group, and maintain test cases. Selenium allows integration with JUnit. To combine the two, one has to write Selenium test code within JUnit test classes.

What is Automation Testing?

View answer

Automated testing is a process that validates if software is functioning appropriately and meeting requirements before it is released into production. This software testing method uses scripted sequences that are executed by testing tools.

What is the difference between “/” and “//” in Xpath?

View answer

Single Slash “/” – Single slash is used to create Xpath with absolute path i.e. the xpath would be created to start selection from the document node/start node.

Double Slash “//” – Double slash is used to create Xpath with relative path i.e. the xpath would be created to start selection from anywhere within the document.

How to type in a textbox using Selenium?

View answer

The following are the two different ways you can type text into the text box fields in Selenium:

  • sendKeys() – driver.findElement().sendKeys();
  • JavascriptExecutor. – JavascriptExecutor jse = (JavascriptExecutor)driver; – jse. executeScript(“document. getElementById(“input-email”). setAttribute('value','QAFox')”);

How can we get a text of a web element?

View answer

We can get text from a webelement with Selenium webdriver. The getText() methods obtains the innerText of an element. It fetches the text of an element which is visible along with its sub elements. It ignores the trailing and leading spaces.

What is the use of findElement() and findElements()?

View answer

The methods findElements and findElement are used to identify elements on a webpage. While findElement can pinpoint only one element, the findElements method yields a list of matching web elements.

How would you handle windows based pop up with Selenium?

View answer

Selenium is an automation testing tool which supports only web application testing, that means, it does not support testing of windows based applications. However with some third-party tools, this can be done. There are several third-party tools available for handling window based pop-ups with the Selenium like AutoIT, Robot class etc.

What is Object Repository?

View answer

An Object Repository is a map between UI element and its locator. Which can also be written as an Object Map between UI element and the way to find it. In Selenium WebDriver's context it means a Mapping between WebElement and the corresponding locator type and value.

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

View answer

setSpeed sets a speed that will apply a delay time before every Selenium operation. thread. sleep() will set up wait only for once when called.

What are heightened privileges browsers?

View answer

The purpose of heightened privileges is similar to Proxy Injection, allows websites to do something that are not commonly permitted. The key difference is that the browsers are launced in a special mode called heightened privileges. By using these browser mode, Selenium core can open the AUT directly and also read/write its content without passing the whole AUT through the Selenium RC server.

Compare Implicit wait and Explicit wait.

View answer

The Implicit Wait in Selenium is used to tell the web driver to wait for a certain amount of time before it throws a “No Such Element Exception”. The default setting is 0. Once we set the time, the web driver will wait for the element for that time before throwing an exception.

The Explicit Wait in Selenium is used to tell the Web Driver to wait for certain conditions (Expected Conditions) or maximum time exceeded before throwing “ElementNotVisibleException” exception. It is an intelligent kind of wait, but it can be applied only for specified elements. It gives better options than implicit wait as it waits for dynamically loaded Ajax elements.

What is Object Repository?

View answer

A basic object repository can be implemented as a collection of key-value pairs, with the key being a logical name identifying the object and the value containing unique objects properties used to identify the object on a screen.

How does the Selenium Grid work?

View answer

Selenium Grid is a smart proxy server that makes it easy to run tests in parallel on multiple machines. This is done by routing commands to remote web browser instances, where one server acts as the hub. This hub routes test commands that are in JSON format to multiple registered Grid nodes.

Why do we use TestNG with Selenium RC?

View answer

Selenium IDE is great for creating test cases and executing single tests. TestRunner is ok at running a test suite. But if you want full automation against different server and client platforms, you need a way to invoke the tests from a command line process, flexibility in how you create your test suites, and reports that tell you what happened. This is where TestNG comes in.

How would you identify an object using selenium?

View answer

To identify an object using Selenium you can use isElementPresent(String locator).

isElementPresent takes a locator as the argument and if found returns a Boolean.

What are Listeners in Selenium?

View answer

Listener is defined as interface that modifies the default TestNG's behavior. As the name suggests Listeners “listen” to the event defined in the selenium script and behave accordingly. It is used in selenium by implementing Listeners Interface. It allows customizing TestNG reports or logs.

Define DesiredCapabilities.

View answer

DesiredCapabilities are a set of key-value pairs encoded as a JSON object. It helps QAs define basic test requirements such as operating systems, browser combinations, browser versions, etc. within Selenium test scripts.