Since there is so much dependency on the web today, ensuring the up-time and functioning of web apps is an evident need. Selenium is an automation testing tool developed precisely for that purpose, and this blog lists the commonly asked Selenium Interview Questions for those(freshers & experienced) getting into the testing domain.
Before I begin discussing the questions, I’d like to emphasize that Manual testing is time-consuming, tedious, boring, and prone to errors. This gives stand up to automation testing and in-turn, call for Selenium automation testers.
Benefits Of Automation Testing
Putting the technical questions aside, you would possibly even be asked a few Selenium tricky interview questions, concerning why only Selenium, and not the other tool? That is because Selenium is open source and its easy adoption has earned itself the tag of being the poster child of web testing tools. With a huge 300 per cent growth in job postings over the past three years, testing has presented itself as an entry point into the IT world for professionals from various domains. Organizations are hunting for professionals with Selenium certification.
So, read the whole list of Java interview questions for Selenium covered during this blog and prepare yourself for an employment interview of a Selenium tester. Let’s get started!
Selenium may be a cross-platform and portable automation testing framework created by Jason Huggins in 2004.
It has seen specific improvement since then, WebDriver 2.0 in 2011, and 3.0 in 2016. Check the below Selenium timeline.
We can use Selenium to write down automation scripts for testing web applications. It helps in reducing manual testing efforts, improves productivity and quality.
Cross-platform means a Selenium script written on one OS say Windows can run on other supported systems like Linux or Mac OS without making any changes. Mobile means the same script created for a desktop-constructed device can go on different supported devices such as tablets, mobiles, etc.
Selenium RC a.k.a. Remote Control came out in early 2004.
It exposed a group of client APIs which use to send commands to a server to perform actions on the browser.
Selenium 2.0 a.k.a. WebDriver may be a set of native APIs which directly send commands to the browser rather than delegating to a server.
Its release came out in 2011. It furnished the native WebDriver API interface and returned the old client-server API model.
It was a major WebDriver upgrade which landed up in 2016.
It is superior to 2.0 because it implemented the W3C specifications for Webdriver APIs to make them a global standard.
Until 3.0, it had been the Selenium community that was supplying Web drivers for specific browsers. But now, they supply their respective drivers that support the quality Web driver API interface.
Below diagram explains the newest architecture Selenium Webdriver supports.
Selenium is an automation development kit that comprises the subsequent components.
A Firefox extension to record and play the user actions performed on an internet page.
A Selenium remote which exposes APIs for scripting tests in several languages and also runs them in browsers.
These are mother APIs that directly interconnect with the browser. They give more control and are faster than the RC APIs.
It provides concurrency. With its help, we can split testing and run a set of cases on one machine and some on another.
Selenium RC had a posh architecture, whereas WebDriver removed those complications. The below points discuss why WebDriver is best than the RC.
There are numerous benefits of using Selenium for automated testing.
Selenium may be a perfect clinical tool to impersonate user actions during a browser. However, it also has a few limitations given below.
The differences are listed below.
Selenium vs HP QTP vs TestComplete
Features
Selenium
HP QTP
TestComplete
License
Open Source
Selenium v1 included only three suites of tools: Selenium IDE, Selenium RC and Selenium Grid. There was no WebDriver in Selenium v1. Selenium WebDriver was introduced in Selenium v2. With the onset of WebDriver, Selenium RC got deprecated and isn’t in use since. Older versions of RC are available in the market though, but support for RC is not available. Currently, Selenium v3 is in use, and it comprises IDE, WebDriver and Grid. Selenium 4 is actually the latest version. The release is not yet announced but was announced in a conference in October 2019.
IDE is hired for recording and playback of tests, WebDriver is hired for testing agile web applications via a programming link and Grid is employed for deploying tests in remote host machines.
Exceptions in Selenium are almost like exceptions in other programming languages. The most common exceptions in Selenium are:
An exception test is an exception that you simply expect to be thrown inside a test class. If you have written a test case in such a way that it should throw an exception, then you can use the @Test annotation and specify which exception you will be expecting by mentioning it in the parameters. Take a glance at the instance below: @Test(expectedException = NoSuchElementException.class)
Do record the syntax, where the exception is suffixed with .class
The reason we use Excel sheets is that it can be used as a data source for tests. An excel sheet also can be wont to store the info set while performing DataDriven Testing. These are the two main reasons for using Excel sheets.
When you use the excel sheet as data source, you’ll store the following:
Selenium supplies a PROXY class to switch browsing from a proxy. Look at the example below:
String PROXY = “199.201.125.147:8080”;
org.openqa.selenium.Proxy proxy = new.org.openqa.selenium.Proxy();
proxy.setHTTPProxy(Proxy)
.setFtpProxy(Proxy)
.setSslProxy(Proxy)
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new FirefoxDriver(cap);
Page Object Model may be a design pattern for creating an Object Repository for web UI elements. Each website within the application is required to possess its own corresponding page class. The page class is thus liable for finding the WebElements therein page then perform operations on those WebElements.
The advantages of using POM are:
Page Factory gives an optimized thanks to implementing the Page Object Model. When we say it is optimized, it refers to the fact that memory utilization is very good and also the implementation is done in an object-oriented manner.
Page Factory is employed to initialize the weather of the Page Object or instantiate the Page Objects itself. note for elements also can be generated (and recommended) because the describing properties might not always be descriptive enough to differentiate one object from the opposite.
The concept of splitting the Page Object depot and Test Methods is followed here also. Instead of having to use
@FindBy will accept tagName, partialLinkText, name, linkText, id, css, class & xpath as attributes.
There are basically two sorts of wait statements: Implicit Wait and Explicit Wait.
Implicit wait instructs the WebDriver to attend for a few by polling the DOM. Once you have declared implicit wait, it’ll be available for the whole lifetime of the WebDriver instance. By default, the value will be 0. If you set a longer default, then the behaviour will poll the DOM on a periodic basis depending on the browser/ driver implementation.
Selenium Certification Training
Instructor-led Sessions
Assessments
AssignmentLifetime Access
Explicit wait instructs the execution to attend for a few time until some condition is achieved. Some of those conditions to be attained are:
elementToBeClickable
elementToBeSelected
presenceOfElementLocated
We can write code such that we specify the XPath of the online element that must be visible on the page and then ask the WebDriver to attend for a specified time. Look at the sample piece of code below:
1
2
WebDriverWait wait=new WebDriverWait(driver, 20);
Element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( “<xpath”)));
Similarly, we can write another piece of code asking the WebDriver to wait until an error appears like this:
1
2
WebDriverWait wait=new WebDriverWait(driver, 20);
Element = wait.until(ExpectedConditions.alertIsPresent());
JavaScriptExecutor is an interface that provides a mechanism to execute Javascript through the Selenium WebDriver. It provides “executescript” and “executeAsyncScript” methods, to run JavaScript in the context of the currently selected frame or window. An example of that is:
1
2
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(Script,Arguments);
We can scroll down a page by using window.scrollBy() function. Example:
1
((JavascriptExecutor) driver).executeScript(“window.scrollBy(0,500)”);
To scroll down to a particular element on a web page, we can use the function scrollIntoView(). Example:
1
((JavascriptExecutor) driver).executeScript(“arguments[0].scrollIntoView();”, element);
We can handle special keyboard and mouse events by using Advanced User Interactions API. The Advanced User Interactions API contains the Actions and the Action Classes that are needed for executing these events. Most commonly used keyboard and mouse events provided by the Actions class are in the table below:
Selenium functions and their explanation
Method | Description |
clickAndHold() | Clicks (without releasing) the current mouse location. |
dragAndDrop() | Performs click-and-hold at the location of the source element, moves. |
source, target() | Moves to the location of the target element, then releases the mouse. |
Selenese is the set of Selenium commands which are used to test your web application. The tester can test the broken links, the existence of some object on the UI, Ajax functionality, alerts, window, list options and a lot more using Selenese.
Action: Commands which interact directly with the application
Accessors: Allow the user to store certain values to a user-defined variable
Assertions: Verifies the current state of the application with an expected state
Selenium
Selenium supports the following types of testing:
Functional Testing
Regression Testing
Following are the limitations of Selenium:
Feature | Selenium IDE | Selenium RC | WebDriver |
Browser Compatibility | Selenium IDE comes as a Firefox plugin, therefore it underpins just Firefox | Selenium RC supports various versions of Google Chrome, Internet Explorer, Mozilla Firefox and Opera. | WebDriver supports a varied range of versions of Mozilla Firefox, Google Chrome, Internet Explorer and Opera. |
Record and Playback | Selenium IDE supports record and playback feature | Selenium RC doesn’t support record and playback features. | WebDriver doesn’t support record and playback feature |
Server Requirement | Selenium IDE does not require any server to be initiated before running the test scripts | Selenium RC requires the server to be started before executing the test scripts. | WebDriver does not require any type of server to be started before running the test scripts |
Architecture | Selenium IDE is a Javascript based framework | Selenium RC is a JavaScript based Framework. | WebDriver uses the browser’s native compatibility to automation |
Object Oriented | Selenium IDE is not an object oriented tool | Selenium RC is a semi object oriented tool. | WebDriver is a purely object oriented tool |
Dynamic Finders (for locating web elements on a webpage) | Selenium IDE doesn’t support dynamic finders | Selenium RC doesn’t support dynamic finders. | WebDriver supports dynamic finders |
Handling Alerts, Navigations, Dropdowns | Selenium IDE does not explicitly provides aids to navigations, handle alerts, dropdowns | Selenium RC does not explicitly provide aids to navigations, handle alerts, dropdowns. | WebDriver provides a wide range of classes and utilities that guides in navigations, handling alerts, and dropdowns effectively and efficiently. |
WAP (iPhone/Android) Testing | Selenium IDE doesn’t support testing of iPhone/Android applications | Selenium RC doesn’t support testing of iPhone/Android applications. | The tool comes with a huge number of drivers for WAP based testing. For example, AndroidDriver, iPhoneDriver |
Listener Support | Selenium IDE doesn’t support listeners | Selenium RC doesn’t support listeners. | WebDriver supports the implementation of Listeners |
Speed | IDE and browser communicates directly | Selenium RC is slower than WebDriver. | WebDriver communicates directly with the web browsers. Thus making it much faster. |
Selenium IDE is the simplest and easiest of all the tools within the Selenium Package. Its record and playback feature makes it exceptionally easy to learn with minimal acquaintances to any programming language. Selenium IDE is a perfect tool for a naïve user.
Selenese is the language which is employed to write down test scripts in Selenium IDE.
The locator is often termed as an address that identifies an internet element uniquely within the webpage. Thus, to mark online elements correctly and absolutely we’ve differing types of locators in Selenium:
Assert: declare command checks whether the given condition is correct or wrong. Let’s say we assert whether the given element is present on the online page or not. If the condition is true then the program control will execute the subsequent test step but if the condition is fake, the execution would stop and no further test would be executed.
confirm: confirm command also checks whether the given condition is true or false. Irrespective of the condition being correct or wrong, the program execution doesn’t halt i.e. any failure during verification wouldn’t stop the execution and every one the test steps would be executed.
XPath is employed to locate an internet element supporting its XML path. XML stands for Extensible terminology and is employed to store, organize and transport arbitrary data. It stores data during a key-value pair which is extremely much almost like HTML tags. Both being markup languages and since they fall into an equivalent umbrella, XPath are often wont to locate HTML elements.
The basic behind finding elements using XPath is that the traversing between various elements across the whole page and thus enabling a user to seek out a component with the reference of another element.
Single Slash “/” – Single slash is employed to make Xpath with absolute path i.e. the xpath would be created to start out the selection from the document node/start node.
Double Slash “//” – Double slash is employed to make Xpath with relative path i.e. the xpath would be created to start out the selection from anywhere within the document.
The problem of same-origin policy disallows access to the DOM of a document from an origin that’s different from the origin we try to access the document.
So, so as to handle the same-origin policy, a Selenium remote was introduced.
Selenium Grid is often wont to perform the same or differently. trial scripts on different platforms and browsers simultaneously so on achieve give out test execution, testing under different environments and saving execution time remarkably.
Selenium RC and WebDriver, during a combination, are popularly referred to as Selenium 2. Selenium RC alone is additionally mentioned as Selenium 1.
WebDriver
The following syntax are often wont to launch Browser:
WebDriver driver = new FirefoxDriver();
WebDriver driver = new ChromeDriver();
WebDriver driver = new InternetExplorerDriver();
The different drivers available in WebDriver are:
There are two sorts of waits available in WebDriver:
Implicit Wait
Explicit Wait
The user can use sendKeys(“String to be entered”) to enter the string in the textbox.
Syntax:
WebElement username = drv.findElement(By.id(“Email”));
// entering username
username.sendKeys(“sth”);
WebDriver facilitates the user with the subsequent methods to see the visibility of the online elements. These web elements are often buttons, drop boxes, checkboxes, radio buttons, labels etc.
isDisplayed()
isSelected()
isEnabled()
Syntax:
isDisplayed():
boolean buttonPresence = driver.findElement(By.id(“gbqfba”)).isDisplayed();
isSelected():
boolean butt driver.findElement(By.id(“gbqfba”)).isSelected();
isEnabled():
boolean searchIconEnabled = driver.findElement(By.id(“gbqfb”)).isEnabled();
Get command is employed to retrieve the inner text of the required web element. The command doesn’t need any parameters but give back a string value. It is also one among the extensively used commands for verification of messages, labels, errors etc displayed on the online pages.
Syntax:
String Text = driver.findElement(By.id(“Text”)).getText();
The values within the dropdown are often selected using WebDriver’s Select class.
Syntax:
selectByValue:
Select selectByValue = new Select(driver.findElement(By.id(“SelectID_One”)));
selectByValue.selectByValue(“greenvalue”);
selectByVisibleText:
Select selectByVisibleText = new Select (driver.findElement(By.id(“SelectID_Two”)));
selectByVisibleText.selectByVisibleText(“Lime”);
selectByIndex:
Select selectByIndex = new Select(driver.findElement(By.id(“SelectID_Three”)));
selectByIndex.selectByIndex(2);
: Both assert and verify commands are responsible for checking whether the given condition is true or false. However, the most distinction between the 2 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’s true or false, the program execution continues and every one the test steps are going to be completed.
The WebDriver component of the Selenium suite facilitates checking the visibility of web elements, which may 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 butt driver.findElement(By.id(“some id”)).isSelected();
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 weather from an origin that’s different from where it had been launched. Selenium remote was introduced so as to handle the matter of Same Origin Policy.
Selenium supplies Native APIs for interacting with the browser utilizing actions and events. The Rest API and therefore the web services don’t have any UI and hence can’t be automated using Selenium.
Following are the web drivers supported in Selenium.
The following characteristics of Selenium make 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. |
There are four parameters in Selenium which includes:
The part of set Speed() and Sleep() in Selenium is to detain the speed of execution.
Heightened privileges browsers act as proxy injections that allow different websites to try things that are normally not permitted. These browsers allow Selenium core to open the AUT directly and thereby read and write its content without passing the entire AUT through the Selenium RC server.
55.what is a Borland Silk Test Tool?
A Borland Silk Test Tool is employed for the client-server application employing a test scripting language.
A Selenium Test Tool is employed for web applications and has the pliability to several languages, including JAVA, Perl, Ruby, and various others.
Webdriver doesn’t require the Selenium Server because it uses a totally different technology. It supplies Selenium RC performance, which supplies backward compatibility to Selenium 1.0. Also, it makes a direct call to the various browsers for making automation. At an equivalent time, within the case of Selenium RC, it requires the Selenium Server to input the Javascript into the browser.
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. | Can also 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. |
Following are the navigation commands:
navigate().back() – The above command requires no parameters and takes back the user to the previous webpage within the web browser’s history.
Sample code:
driver.navigate().back();
navigate().forward() – This command lets the user to navigate to the subsequent website with regard to the browser’s history.
Sample code:
driver.navigate().forward();
navigate().refresh() – This command lets the user to refresh the present website there by reloading all the online elements.
Sample code:
driver.navigate().refresh();
navigate().to() – This command lets the user to launch a replacement browser window and navigate to the required URL.
Sample code:
driver.navigate().to(“https://google.com”);
driver.findElement(By.linkText(“Google”)).click();
The command finds the element using link text and then click on that element and thus the user would be redirected to the corresponding page.
The above-mentioned link can also be accessed by using the following command.
driver.findElement(By.partialLinkText(“Goo”)).click();
The above command finds the element based on the substring of the link provided in the parenthesis and thus partialLinkText() finds the web element with the specified substring and then clicks on it.
61.How to capture a screenshot in WebDriver?
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class CaptureScreenshot {
WebDriver driver;
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
driver.get(“https://google.com”);
}
@After
public void tearDown() throws Exception {
driver.quit();
}
@Test
public void test() throws IOException {
// Code to capture the screenshot
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Code to copy the screenshot in the desired location
FileUtils.copyFile(scrFile, new File(“C:\\CaptureScreenshot\\google.jpg”))
62 What is Junit?
Junit may be a unit testing framework introduced by Apache. Junit is based on Java.
Following are the JUnit Annotations:
TestNG is a complicated framework designed thanks to leveraging the advantages of both the developers and testers. With the beginning of the frameworks, JUnit gets huge popularity across the Java applications, Java developers and Java testers with remarkably increasing the code quality. In spite of being easy to use, JUnit has its own curb which makes the necessity of bringing TestNG into the image. TestNG is an open-source framework which is distributed under the Apache Software License and is quickly available for download.
TestNG with WebDriver supplies a successful test result format which will, in turn, be shared with the stakeholders to possess a glimpse on the product’s/application’s health thereby eliminating the drawback of WebDriver’s incapability to get test reports. TestNG has an innate deviation handling mechanism which lets the program to run without terminating unexpectedly.
There are different advantages that make TestNG senior to JUnit. Some of them are:
Added advance and easy annotation
Execution patterns can set
Concurrent execution of test scripts
Test case dependencies can be same
Setting Priority in TestNG
Code Snippet
package TestNG;
import org.testng.annotations.*;
public class SettingPriority {
@Test(priority=0)
public void method1() {
}
@Test(priority=1)
public void method2() {
}
@Test(priority=2)
public void method3() {
}
}
Test Execution Sequence:
Method1
Method2
Method3
Test data can successfully be read from excel using JXL or POI API. See detailed tutorial here.
#
JXL jar
POI jar
1
JXL supports “.xls” format i.e. binary-based format. JXL do not support Excel 2007 and “.xlsx” format i.e. XML based format
POI jar supports all of these formats
2
JXL API was last updated within the year 2009
POI is regularly updated and released
3
The JXL documentation isn’t as comprehensive as that of POI
POI features a well prepared and highly comprehensive documentation
4
JXL API doesn’t support rich text formatting
POI API supports rich text formatting
5
JXL API is faster than POI API
POI API is slower than JXL API
Sometimes we get demented while differentiating between the MaxSessions vs. MaxInstances. Let’s understand the difference with clarity.
-browser browserName=firefox,version=59,maxInstances=3,platform=WINDOWS
-browser browserName=InternetExplorer,version=11,maxInstances=3,platform=WINDOWS
It means we can run three instances of both Firefox and IE at the same time. So, a total of six different browsers (FF & IE) could run in parallel.
In the previous example: If the worth of “maxSession” is one, then no quite one browser would run. While its value is two, then any of these combinations (2FF, 2IE, 1FF+1IE) can run at a time.
69.Can WebDriver test Mobile applications?
WebDriver cannot test Mobile applications. WebDriver may be a web-based testing tool, therefore applications on the mobile browsers are often tested.
70.Can captcha be automated?
No, captcha and barcode readers cannot be automated.
Object Repository may be a term to ask the gathering of web elements belonging to Application Under Test (AUT) alongside their locator values. Thus, whenever the element is required within the script, the locator values are often populated from the thing Repository. Object Repository is employed to store locators during a centralized location rather than hardcoding them within the scripts.
In Selenium, objects can be stored in an excel sheet that can be populated inside the script whenever required.
That’s all for now.
So this brings us to the top of the Selenium interview questions blog. Alternatively, you’ll inspect this video on Selenium interview questions delivered by an industry expert where he also talks about the industry scenario and the way questions are going to be twisted and asked in an interview. In this, we just state the timeout value only. We will make the tool to attend until a particular amount of your time then proceeds further.
Hope during this article you’ll find answers to most often asked Selenium and WebDriver Interview questions. The answers provided here also are helpful for understanding the Selenium basics and advanced WebDriver topics.
Do you have any Selenium Interview questions that aren’t answered here? Please let us know in the comments below and we will try to answer all.
ITCourCes.com under SOWPRA LEARNINGS PRIVATE LIMITED is an online platform designed to solve the needs of aspirants to learn diverse IT Courses from industry expert trainers. We provide 24/7 support and can guide seekers to get right material as per their requirement.