Interview Questions and Selenium

Selenium Interview Questions

Posted in Interview Questions, Selenium
Selenium Interview Questions

Table of Contents

Every aspiring tester, especially one aiming to work with web-based applications, must have good knowledge about Selenium. This is because whenever applying for some job opportunity regarding web-based testing these days, expect Selenium-based questions coming your way.

Written completely in Java, Selenium is one of the most widely used automation testing tools. It is easy to use, simple and provides support for writing test scripts in a wide variety of programming languages, including C#, Groovy, Java, Perl, and Python.

Selenium Interview Questions

Here, we have collected the top Selenium interview questions that will help you append your extant Selenium knowledge as well as check how well you fare against an array of Selenium interview questions thrown right at you. So, let’s jump right into it:

Question: Please explain the various Selenium components.

Answer: Although labeled as an automation testing tool, Selenium isn’t a standalone tool. Instead, it is a package of several tools, and thus a testing suite. The Selenium suite has the following components:

  • Selenium IDE – Distributed as a Firefox plugin, Selenium IDE serves as a record and playback tool.
  • Selenium Grid – Allows distributing test execution across multiple platforms and environments concurrently.
  • Selenium RC – A server that allows users to create test scripts in a desirable programming language. Selenium RC also permits executing test scripts across a diverse range of web browsers.
  • Selenium WebDriver – Communicated directly with the web browser in addition to using its native compatibility to automate.

Question: Could you state the limitations of Selenium?

Answer:

  • Although Selenium has an active community support, no vendor support is available
  • No built-in report generation. Third-party tools like JUnit and TestNG need to be used
  • Not able to offer testing for barcode and captcha readers
  • Requires good programming language knowledge
  • Supports testing of only web-based applications. Hence, doesn’t provide support for testing mobile applications

Question: What are the different types of locators in Selenium?

Answer: A locator is a kind of address that offers a unique way of identifying a web element on the webpage. Selenium has a range of locators to identify different elements of a webpage, namely:

  • ClassName
  • CSS Selector
  • DOM
  • ID
  • LinkText
  • Name
  • PartialLinkText
  • TagName
  • XPath

QuestionCan you explain the difference between assert and verify commands in Selenium?

Answer: Both assert and verify commands are responsible for checking whether the given condition is true or false. However, the main distinction between the two lies what each of them does after the condition checking is complete.

If the condition comes out to be false in the case of a verify command, then the execution stops and no further tests will be executed. However, if the condition is true then the program control will continue executing the next test step.

Verify command, on the other hand, does not care about the result of the condition checking. Whether it is true or false, the program execution continues and all the test steps will be completed.

QuestionWhat do you understand by XPath in Selenium? Can you tell the difference between “/” and “//” in XPath?

Answer: XPath is a type of locator in Selenium that is used to locate a web element based on its XML path. XML denotes Extensible Markup Language, which is used for storing, organizing, and transporting arbitrary data. Much like HTML tags, XML stores data in a key-value pair.

Since HTML and XML both are markup languages, XPath can be used for locating HTML elements on a webpage. The underlying principle of XPath is traversing between several elements across the entire webpage and allowing them to find an element with the reference of some other element.

The single slash i.e. ‘/’ is used to create XPath with the absolute path, while the double slash i.e. ‘//’ is used for creating XPath with the relative path.

In the absolute path, the created XPath will start selection from the document node or the start node. However, in the relative path, the created XPath can start selection from anywhere within the entire web document.

QuestionHow will you launch the browser using WebDriver?

Answer: The syntax used for launching Google Chrome, Mozilla Firefox, and Internet Explorer using WebDriver is respectively,

  • WebDriver driver = new FirefoxDriver();
  • WebDriver driver = new ChromeDriver();
  • WebDriver driver = new InternetExplorerDriver();

QuestionPlease explain how to find if an element is displayed on the screen.

Answer: The WebDriver component of the Selenium suite facilitates checking the visibility of web elements, which can be buttons, checkboxes, drop boxes, labels, radio buttons, et cetera. WebDriver allows doing so with the following three methods:

  • isDisplayed()
    boolean buttonPresence = driver.findElement(By.id(“some id”)).isDisplayed();
  • isEnabled()
    boolean searchIconEnabled = driver.findElement(By.id(“some id”)).isEnabled();
  • isSelected()
    boolean buttonSelected = driver.findElement(By.id(“some id”)).isSelected();

QuestionWhat do you mean by Same Origin Policy? How to handle it?

Answer: An Origin is a sequential combination of host, scheme, and port of the URL. The issue of the same-origin policy restricts accessing the DOM of a document from an origin that is different from the one that a user is trying to access the document.

The Selenium Core isn’t allowed to access the elements from an origin that is different from where it was launched. Selenium Remote Control was introduced in order to handle the problem of Same Origin Policy.

QuestionDo you know how to get a text of a web element using Selenium?

Answer: In order to retrieve the inner text of a specified web element, Selenium offers the get command. It returns a string value and doesn’t require any parameters. Get command is one of the most widely used commands for verifying errors, labels, messages, etc. displayed on webpages. The general syntax for the get command is:

String Text = driver.findElement(By.id(“Text”)).getText();

QuestionPlease enumerate the various types of Drivers and Waits available in WebDriver.

Answer: WebDriver provides support for the following drivers:

  • AndroidDriver
  • ChromeDriver
  • FirefoxDriver
  • HtmlUnitDriver
  • InternetExplorerDriver
  • IPhoneDriver
  • OperaDriver
  • SafariDriver

There are two types of waits available in WebDriver, explained as follows:

  • Implicit Wait – Used for providing a default waiting time between each successive test step or command across the entire test script. Hence, the next test step or command will only execute when the set default waiting time, say 30 seconds, have passed since the execution completion of the previous test step or command. Can be applied to a particular instance or several instances.
  • Explicit Wait – Used for halting the execution until the occurrence of a particular condition or till the elapsing of the maximum time. Applied for a particular instance only.

Question: What do you understand by Object Repository? How do you create one in Selenium?

Answer: The term Object Repository refers to the collection of web elements that belong to AUT (Application Under Test) and their locator values. A corresponding locator value can be populated from the Object Repository whenever an element is required within the script.

Instead of hardcoding locators within the scripts, they are stored in a centralized location using Object Repository. Typically, the objects are stored in an excel sheet in Selenium which acts as the Object Repository.

Answer: The following command finds a specified element using the linkText() method and then clicks on that element to redirect the user to the corresponding webpage:

driver.findElement(By.linkText(“Google”)).click();

Another command that can be used for the same purpose is:

driver.findElement(By.partialLinkText(“Goo”)).click();

In this command, we use the partialLinkText() method. The aforementioned command finds the element based on the substring, Goo in this case, of the link provided.

Question: What is the most important difference between driver.close() and driver.quit() commands in Selenium?

Answer: The close() method closes the currently accessed window by the WebDriver. Neither does the command requires any parameter nor does it returns any value.

Unlike the close() method, the quit() method is used for closing down all the windows opened by the program. Like close() command, the quit() method doesn’t require any parameter nor does have any return value type.

Question: How will you find more than one web element in the list using Selenium?

Answer: Selenium offers WebElement List for finding more than a single web element in the list. Its use is demonstrated by the following code snippet:

List elementList =
driver.findElements(By.xpath(“//div[@id=‘example’]//ul//li”));
Int listSize = elementList.size();
for (int i=0; i<listSize; i++)
{
serviceProviderLinks.get(i).click();
driver.navigate().back();
}

Question: Can you explain the differences between Selenium and QTP?

Answer:

  • Availability – Selenium is an open-source and free-to-use testing tool. QTP, on the other hand, is a licensed and commercial testing tool.
  • Browser Compatibility – While QTP provides support for only Chrome, Firefox, and Internet Explorer, Selenium can be used with the aforementioned plus Opera, Safari, and several others.
  • Object Repository – QTP automatically creates and maintains an Object Repository. However, this is not the case with Selenium as one needs to create an Object Repository while working with the automation testing tool.
  • Programming Language Support – The only programming language supported by QTP is VB but Selenium provides support for a multitude of programming languages, including C#, Java, Perl, Python, and Ruby.
  • Testing Support – Whereas Selenium offers testing of only web applications, QTP provides testing support for both web-based and Windows-based applications.
  • Vendor Support – No vendor support is available with Selenium while the same is available for QTP.

Question: How will you handle web-based pop-ups in Selenium?

Answer: WebDriver allows handling web-based pop-ups via the Alert interface. The general syntax is:

Alert alert = driver.switchTo().alert();
alert.accept();

A total of 4 methods are available for handling the web-based pop-ups, namely:

  • String getText() – Returns text displayed on the alert box
  • void accept() – Clicks on the ‘Ok’ button as soon as the pop-up appears
  • void dismiss() – Clicks on the ‘Cancel’ button as soon as the pop-up appears
  • void sendKeys(String stringToSend) – Inputs a specified string pattern in the alert box

Question: Can you explain the various types of navigation commands supported by Selenium?

Answer: Selenium supports a total of 4 navigation commands, listed as follows:

  • navigate().back() – Takes the user back to the previous webpage as per the web browser history. Requires no parameters
  • navigate().forward() – Navigates the user to the next webpage in the web browser history. Requires no parameters
  • navigate().refresh() – Reload all the web elements by refreshing the current webpage. Requires no parameters
  • navigate().to() – Lets the user launch a new web browser window and navigate to the specified URL given as a parameter

QuestionWhen should we use findElement() and findElements()?

Answer: findElement() – Used for finding the first element in the current webpage matching to the specified locator value. Irrespective of the number of positive matches, only the first element will be fetched. Its general syntax is:

WebElement element = driver.findElements(By.xpath(“//div[@id=’some id’]//ul//li”));

findElements() – Used for finding all elements matching the specified locator value in the current webpage. All matching elements will be fetched and stored in the list of WebElements. The general syntax for the method is:

List elementList = driver.findElements(By.xpath(“//div[@id=’some id’]//ul//li”));

Question: What is JUnit? Explain the various JUnit annotations.

Answer: JUnit is a Java-based testing framework from Apache that complements Selenium. Various JUnit Annotations are enumerated as follows:

  • @After – Lets the system know that this method will be executed every time a test method achieves completion
  • @AfterClass – Lets the system know that this method must be executed once after any of the test methods
  • @Before – Lets the system know that this method will be executed just before every time a test method starts execution
  • @BeforeClass – Lets the system know that this method must be executed once before any of the test methods start execution
  • @Ignore – Lest the system know that this method shall be ignored i.e. it shall not be executed
  • @Test – Lets the system know that this method is a test method. It is possible to have several test methods in a single test script

Question: Please explain the various types of Test Automation Frameworks.

Answer:

  • Behavior-Driven Development Framework – Allows automating functional validations in an easy-to-read and understandable format for different professionals, including analysts, developers, and testers.
  • Data-Driven Testing Framework – Helps in segregating the test script logic and the test data. Allows storing test data in some external database in the form of key-value pairs. These keys are used for accessing as well as populating the data within the test scripts.
  • Keyword-Driven Testing Framework – It is an extension to the data-driven testing framework in a way that in addition to separating test data from the test scripts, a keyword-driven testing framework stores a part of the test script code in an external data file.
  • Library Architecture Testing Framework – Works on the principle of determining the right steps and then grouping them together into functions under a library. These functions are called in the test scripts whenever required.
  • Module-Based Testing Framework – Divides each application under testing into a number of logical and isolated modules. A distinct test script is created for each module.
  • Hybrid Testing Framework – Offers features belonging to different types of testing frameworks. The idea is to reap in all the benefits of various approaches with a single testing tool.

Question: What is Selenium? Define its composition?

Answer: Selenium is a suite of various tools that are used explicitly for automated web testing purposes. Its compositions have Selenium IDE (Integrated Development Environment), WebDriver and RC, and Grid.

Question: How are Selenium 2.0 and Selenium 3.0 different from Selenium?

Answer: Selenium 2.0 has consolidated Selenium RC and WebDriver to make a single tool, while Selenium 3.0 is the latest version, which has Beta 1 and Beta 2 updates.

Question: Identify the various test types that are supported by Selenium?

Answer: The various test types that are supported by Selenium include the following:

  1. Functional.
  2. Regression.
  3. CruiseCont.
  4. Hudson.
  5. Jenkins.
  6. Quick Build.

Question: What is the role of Assertion in Selenium?

Answer: The role of Assertion in Selenium is to act as a verification point. It helps in verifying the state of the application that conforms to expectations. 

Question: What are the various types of Assertion in Selenium?

Answer: There are three types of Assertion in Selenium, which include the following:

  1. Assert.
  2. Verify.
  3. WaitFor.

Question: What are the technical challenges with Selenium?

Answer: There are several technical challenges with Selenium which includes:

  1. It only supports web-based applications.
  2. Bitmap comparison is not supported.
  3. Third-party tools are sought for reporting purposes.
  4. Vendor support is minimal as compared to other commercial tools such as HP UFT.
  5. It is challenging to maintain objects in Selenium.

Question: Differentiate between Type Keys and Type Commands in Selenium?

Answer: Types Keys collects the different value attributes using the JavaScript while the Type Commands imitates like an actual user typing.

Question: Differentiate between Assert and Verify commands?

Answer: Assert commands helps in checking if the element is on the page or not. The test will fail in case of missing the required element and will get terminated. Verify commands helps in checking the element is on the page or not but will not terminate but will continue ahead on executing all the commands.

Question: What are the distinct features of Selenium?

Answer: The distinct features of Selenium include the following:

  1. It supports C#, Python, Perl, JAVA, and PHP.
  2. It can run on various operating systems, including Mac OS, Linux, and Windows.
  3. It can easily locate elements using Xpath, CSS, and DOM.
  4. Its developer community is supported by Google.

Question: What makes Selenium better than QTP?

Answer: The following features of Selenium makes it better than QTP:

Selenium

QTP

It is an open-source

It is a commercial tool

It is used for testing various web-based applications.

It is used for web-based applications and testing client-server applications.

It supports Safari, Opera, and Firefox on Linux, Mac, and Windows.

It supports only the Internet Explorer on Windows.

It supports different programming languages such as Python, Perl, and Ruby.

It supports only VB Script.

Question: Define the parameters in Selenium?

Answer: There are four parameters in Selenium which includes:

  1. Host.
  2. URL.
  3. Port Number.
  4. Browser.

Question: What is the role of set Speed() and Sleep() methods in Selenium?

Answer: The role of set Speed() and Sleep() in Selenium is to delay the speed of execution.

Question: Define heightened privileges browsers?

Answer: Heightened privileges browsers acts as proxy injections that allow different websites to do things that are normally not permitted. These browsers allow Selenium core to pen the AUT directly and thereby read and write its content without passing the whole AUT through the Selenium RC server.

Question: What is a Borland Silk Test Tool?

Answer: A Borland Silk Test Tool is used for the client-server application using a test scripting language.

Question: What is a Selenium Test Tool?

Answer: A Selenium Test Tool is used for web applications and has the flexibility to many languages, including JAVA, Perl, Ruby, and various others.

Question: What are the major differences between Borland Silk Test Tool and Selenium Test Tool?

Answer: The major differences between Borland Silk Test Tool and Selenium Test Tool can be displayed as follows:

Borland Silk Test Tool

Selenium Test Tool

It is not a free testing tool.

It is a free testing tool.

It has to be applied manually.

It is an automation tool.

It supports only Internet Explorer and Firefox.

It supports all kinds of browsers, including Internet Explorer, Firefox, Safari, Opera, and various others.

It is specifically used for testing script language.

It can be applied for testing programs in various languages.

It can be applied to a client-server application.

It can be applied only to web applications.

Question: How is Webdriver beneficial over Selenium Server?

Answer: Webdriver does not require the Selenium Server because it uses a completely different technology. It provides Selenium RC functionality, which provides backward compatibility to Selenium 1.0. Also, it makes a direct call to the various browsers for making automation. At the same time, in the case of Selenium RC, it requires the Selenium Server to input the Javascript into the browser.

Question: What is the other name of Selenium WebDriver?

Answer: The other popular name of Selenium WebDriver is Selenium 2.0

Question: What are the distinct features 0f Selenium WebDriver from Selenium 1.0?

Answer: The distinct features of Selenium WebDriver from Selenium 1.0 includes:

  1. It helps in handling multiple frames, browsers, windows, alerts, and pop-ups.
  2. It helps in-page navigation.
  3. It offers a drag and drop facility on the page.
  4. It applies the Ajax-based User Interface (UI) elements.
  5. It offers multiple browser testing facilities which helps in improving functionality for browsers which were earlier not supported by Selenium 1.0

Question: Can we handle colors in Web Driver?

Answer: Yes, we can handle colors in Web Driver using the getCssValue(arg0) function. It will help in getting the color by sending the 'color' string as an argument.

Question: Can we store a value, which is a text box?

Answer: Yes, we can store a value, which is a text box using Web Driver. We can apply driver.findElement(By.id(“your Textbox”)).sendKeys(“your keyword”);

Question: Can we Switch between frames?

Answer: Yes, we can Switch between frames using the WebDrivers, which can take any arguments.

Question: What are the three arguments that can be taken into consideration for Switching?

Answer: The three arguments that can be taken into consideration for Switching includes:

  1. A number: This will select the number by its zero-based index.
  2. A name or ID: This will select a frame by its name or ID.
  3. Previously found WebElement: This will help in using the previously located WebElement to select a frame.

Question: What are the exceptions to Selenium WebDriver?

Answer: There are five different exceptions to Selenium WebDriver which includes:

  1. TimeoutException.
  2. WebDriverException.
  3. NoAlertPresentException.
  4. NoSuchElementException.
  5. NoSuchWindowException.

Question: Which is the best WebDriver implementation?

Answer: The best WebDriver implementation of the HTML unit is the fastest because it does not execute the tests on the browsers but applies plain HTTP request, which is quick and helps in launching the browser and executing the tests.

Conclusion

Well, that sums up the list of the top Selenium interview questions and answers. Going through the list will surely help you tighten up your preparation for that upcoming Selenium interview. 

Are you looking for more Selenium interview questions? Here is a good course that will help you prepare for an upcoming Selenium Testing Interview Questions: QA preparation for Selenium Automation and Agile Interview.

Some generic data structure-based questions are usual in software testing interviews. Go ahead and consider buying this amazing programming hack book dubbed Cracking the Coding Interview: Cracking the Coding Interview: 189 Programming Questions and Solutions.

Please leave your comments in the comments window below and don’t forget to check out some of the best Selenium tutorials to step up your web-based application testing game. All the best!

People are also reading:

Akhil Bhadwal

Akhil Bhadwal

A Computer Science graduate interested in mixing up imagination and knowledge into enticing words. Been in the big bad world of content writing since 2014. In his free time, Akhil likes to play cards, do guitar jam, and write weird fiction. View all posts by the Author

Leave a comment

Your email will not be published
Cancel
jarek
jarek

I found a bug (without using Selenium:). Correct this one:
"If the condition comes out to be false in the case of a verify command, then the execution stops and no further tests will be executed. However, if the condition is true then the program control will continue executing the next test step."

It's not about verify command, but assert. On assert if it failed, the test will stop.