Top 50 Selenium Interview Questions - Javatpoint
Top 50 Selenium Interview Questions - Javatpoint
Automation testing uses automation tools to write and execute test cases, no manual
involvement is necessary for executing an automated test suite. Testers prefer automation
tools to write test scripts and test cases and then group into test suites.
Automation testing enables the use of specialized tools to automate the execution of
manually designed test cases without any human intervention. Automation testing tools can
access the test data, controls the execution of tests and compares the actual result against
the expected result. Consequently, generating detailed test reports of the system under test.
https://www.javatpoint.com/selenium-interview-questions 2/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
https://www.javatpoint.com/selenium-interview-questions 3/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
Lists of top 10 used automation testing tools for Functional Automation are as follows.
TestingWhiz
Tosca Testsuite
Watir
Lists of some commonly used Automation Testing tools for Non-Functional Automation are as
follows.
https://www.javatpoint.com/selenium-interview-questions 4/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
5) What is Selenium?
Selenium is a portable framework for software testing. Selenium tool facilitates with a
playback tool for authoring functional tests without the need to learn a test scripting
language.
Selenium is one of the most widely used open source Web UI (User Interface) automation
testing suite. Jason Huggins developed Selenium in 2004 as an internal tool at Thought
Works. Selenium supports automation across different browsers, platforms, and
programming languages.
Selenium is not just a single tool but a suite of software's, each having a different approach
to support automation testing. It comprises of four major components which include:
3. WebDriver
4. Selenium Grid
https://www.javatpoint.com/selenium-interview-questions 5/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
Browsers: Google Chrome, Mozilla Firefox, Internet Explorer, Edge, Opera, Safari,
etc.
Selenium v1.0:
It included three tools: Selenium IDE, Selenium RC, and Selenium Grid.
Selenium v2.0:
With the onset of WebDriver, RC got deprecated and moved to the legacy package.
Selenium v3:
The latest release Selenium 3 has new added features and functionalities.
https://www.javatpoint.com/selenium-interview-questions 6/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
Functional Testing
Regression Testing
Sanity Testing
Smoke Testing
Responsive Testing
Integration Testing
Selenium IDE is implemented as Firefox extension which provides record and playback
functionality on test scripts. It allows testers to export recorded scripts in many languages
like HTML, Java, Ruby, RSpec, Python, C#, JUnit and TestNG.
Selenium IDE has limited scope, and the generated test scripts are not very robust, and
portable.
Selenium commands, also known as "Selenese" are the set of commands used in Selenium
that run your tests. For example, command - open (URL); launches the desired URL in the
specified browser and it accept both relative and absolute URLs.
⇧
A sequence of Selenium commands (Selenese) together is known as a test script.
https://www.javatpoint.com/selenium-interview-questions 7/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
In Selenium, web elements are identified and located with the help of Locators. Locators
specify a target location which uniquely defines the web element in the context of a web
application. Thus, to identify web elements accurately and precisely we have different types
of locators in Selenium:
ID
ClassName
Name
TagName
LinkText
PartialLinkText
Xpath
CSS Selector
DOM
The list of WebDriver API's which are used to automate browser include:
AndroidDriver
ChromeDriver
⇧
EventFiringWebDriver
https://www.javatpoint.com/selenium-interview-questions 8/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
FirefoxDriver
HtmlUnitDriver
InternetExplorerDriver
iPhoneDriver
iPhoneSimulatorDriver
RemoteWebDriver
14) List out some of the Automation tools which could be integrated
with Selenium to achieve continuous testing.
Selenium can be used to automate functional tests and can be integrated with automation
test tools such as Maven, Jenkins, &Docker to achieve continuous testing. It can also be
integrated with tools such as TestNG, &JUnit for managing test cases and generating
reports.
The assertion is used as a verification point. It verifies that the state of the application
conforms to what is expected. The types of assertion are "assert", "verify" and "waitFor".
Assert: Assert command checks if the given condition is true or false. If the condition is
true, the program control will execute the next phase of testing, and if the condition is false,
execution will stop, and nothing will be executed.
⇧
https://www.javatpoint.com/selenium-interview-questions 9/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
Verify: Verify command also checks if the given condition is true or false. It doesn't halt
program execution, i.e., any failure during verification would not stop the execution, and all
the test phases would be executed.
XPath is also defined as XML Path. It is a language used to query XML documents. It is an
important approach to locate elements in Selenium. XPath consists of a path expression
along with some conditions. Here, we can easily write XPath script/query to locate any
element in the webpage. It is developed to allow the navigation of XML documents. The key
factors that it considered while navigating are selecting individual elements, attributes, or
some other part of an XML document for specific processing. It also produces reliable
locators. Some other points about XPath are as follows.
XPath can be used as a substitute when you don't have a suitable id or name attribute
for the element you want to locate.
XPath Absolute
XPath Attributes
XPath Absolute:
XPath Absolute enables users to mention the complete XPath location from the root
HTML tag to the specific elements. ⇧
https://www.javatpoint.com/selenium-interview-questions 10/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
Syntax: //html/body/tag1[index]/tag2[index]/.../tagN[index]
Example: //html/body/div[2]/div/div[2]/div/div/div/fieldset/form/div[1]/input[1]
XPath Attributes:
XPath Attributes is always recommended when you don't have a suitable id or name
attribute for the element you want to locate.
Single Slash "/": Single slash is used to create XPath with absolute path.
Double Slash "//": Double slash is used to create XPath with the relative path.
20) What are the different types of annotations which are used in
Selenium?
Test
Before
After
Ignore
BeforeClass
⇧
https://www.javatpoint.com/selenium-interview-questions 11/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
AfterClass
RunWith
AndroidDriver
IphoneDriver
OperaMobileDriver
JAVA
PHP
Python
C#
Ruby
Perl
23) What is the difference between type keys and type commands?
⇧
https://www.javatpoint.com/selenium-interview-questions 12/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
TypeKeys() will trigger JavaScript event in most of the cases whereas .type() won't.
"type" command is used to type keyboard key values into the text box of software web
application. It can also be used for selecting values of combo box whereas "typeAndWait"
command is used when your typing is completed and software web page start reloading.
This command will wait for software application page to reload. If there is no page reload
event on typing, you have to use a simple "type" command.
findElement(): It is used to find the first element within the current page using the given
"locating mechanism". It returns a single WebElement.
findElements(): It uses the given "locating mechanism" to find all the elements within the
current page. It returns a list of web elements.
Selenium Webdriver introduces the concept of waits for the AJAX-based application. There
are two types of waits:
1. Implicit Wait
2. Explicit Wait
⇧
27) What is the main disadvantage of implicit wait?
https://www.javatpoint.com/selenium-interview-questions 13/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
The main disadvantage of implicit wait is that it slows down test performance.
Suppose, you set the waiting limit to be 10 seconds, and the elements appear in the DOM in
11 seconds, your tests will be failed because you told it to wait a maximum of 10 seconds.
Selenium Grid facilitates you to distribute your tests on multiple machines and all of them at
the same time. So, you can execute tests on Internet Explorer on Windows and Safari on
Mac machine using the same text script. It reduces the time of test execution and provides
quick feedback.
Here, "WebDriver" is an interface, and we are creating a reference variable "driver" of type
WebDriver, instantiated using "FireFoxDriver" class.
https://www.javatpoint.com/selenium-interview-questions 14/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
WebDriver driver;
driver = newFirefoxDriver();
driver.get("http://javatpoint.com");
driver.quit();
https://www.javatpoint.com/selenium-interview-questions 15/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "/lib/chromeDriver/chromedriver.exe");
driver = newChromeDriver();
driver.get("http://javatpoint.com");
driver.quit();
https://www.javatpoint.com/selenium-interview-questions 16/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
WebDriver driver;
System.setProperty("webdriver.ie.driver", "/lib/IEDriverServer/IEDriverServer.exe");
driver = newInternetExplorerDriver();
driver.get("http://javatpoint.com");
driver.quit();
We will use Action class to generate user event like right-click an element in WebDriver.
action.contextClick(element).perform();
action.moveToElement(element).perform();
https://www.javatpoint.com/selenium-interview-questions 18/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
.moveToElement(toWebElement)
.release(toWebElement)
.build();
dragAndDrop.perform();
driver.navigate().refresh();
driver.get(driver.getCurrentUrl());
driver.navigate().to(driver.getCurrentUrl());
https://www.javatpoint.com/selenium-interview-questions 19/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
driver.findElement(By textboxLocator).sendKeys(Keys.F5);
5. Passing ascii value of the F5 key, i.e., "\uE035" using the sendKeys command -
driver.findElement(By textboxLocator).sendKeys("\uE035");
driver.navigate().back();
driver.navigate().forward();
driver.get("url"); or
driver.navigate().to("url");
https://www.javatpoint.com/selenium-interview-questions 20/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
Get command is used to get the inner text of the specified web element. The get command
doesn't require any parameter, but it returns a string type value. It is also one of the widely
used commands for verification of messages, labels, and errors,etc.,from web pages.
Syntax
We use the WebDriver's Select class to select the value in the dropdown.
Syntax:
selectByValue:
selectByValue.selectByValue("greenvalue");
⇧
https://www.javatpoint.com/selenium-interview-questions 21/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
selectByVisibleText:
selectByVisibleText.selectByVisibleText("Lime");
selectByIndex.selectByIndex(2);
navigate().back()
The above command needs no parameters and takes back the user to the previous
webpage.
Example
driver.navigate().back();
navigate().forward()
The above command allows the user to navigate to the next web page with reference to the
browser's history.
Example
driver.navigate().forward();
⇧
https://www.javatpoint.com/selenium-interview-questions 22/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
navigate().refresh()
The navigate().refresh() command allows the user to refresh the current web page by
reloading all the web elements.
Example
driver.navigate().refresh();
navigate().to()
The navigate().to() command allows the user to launch a new web browser window and
navigate to the specified URL.
Example
driver.navigate().to("https://google.com");
An inline frame abbreviates as an iframe. It is used to insert another document within the
current document. These document can be HTML document or simply web page and nested
web page.
Select iframe by id
⇧
driver.switchTo().frame(driver.findElements(By.tagName("iframe").get(0));
https://www.javatpoint.com/selenium-interview-questions 23/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
frame(index)
driver.switchTo().frame(0);
frame(Name of Frame)
frame(WebElement element)
driver.switchTo().defaultContent();
To use HtmlUnit first use the RemoteWebDriver and pass it in the desired capabilities.
IWebDriver driver
= new RemoteWebDriver(DesiredCapabilities.HtmlUnit())
IWebDriver driver
= new RemoteWebDriver(DesiredCapabilities.HtmlUnitWithJavaScript())
⇧
https://www.javatpoint.com/selenium-interview-questions 24/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
45) How can you redirect browsing from a browser through some
proxy?
Selenium facilitates with a PROXY class to redirect browsing from a proxy. Look at the
example below.
Example
proxy.setHTTPProxy(Proxy)
.setFtpProxy(Proxy)
.setSslProxy(Proxy)
cap.setCapability(CapabilityType.PROXY, proxy);
46) What is POM (Page Object Model)? What are its advantages?
Page Object Model is a design pattern for creating an Object directory for web UI elements.
Each web page is required to have its page class. The page class is responsible for finding
the WebElements in web pages and then perform operations on WebElements.
It facilitates with separate operations and flows in the UI from Verification - improves
code readability
https://www.javatpoint.com/selenium-interview-questions 25/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
Multiple tests can use the same Object Repository because the Object Repository is
independent of Test Cases.
Reusability of code
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;
WebDriver drv;
@Before
drv.get("https://google.com");
⇧
https://www.javatpoint.com/selenium-interview-questions 26/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
@After
drv.quit();
@Test
Syntax
// entering username
username.sendKeys("sth");
https://www.javatpoint.com/selenium-interview-questions 27/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
WebDriver allows user to check the visibility of the web elements. These web elements can
be buttons, radio buttons, drop, checkboxes, boxes, labels etc. which are used with the
following methods.
isDisplayed()
isSelected()
isEnabled()
Syntax:
isDisplayed():
isSelected():
isEnabled():
driver.findElement(By.linkText("Google")).click();
The above command search the element using a link text, then click on that element and
thus the user will be re-directed to the corresponding page.
driver.findElement(By.partialLinkText("Goo")).click();
⇧
https://www.javatpoint.com/selenium-interview-questions 28/30
3/6/2021 Top 50 Selenium Interview Questions - javatpoint
The above-given command searches the element based on the substring of the link provided
in the parenthesis. And after that partialLinkText() finds the web element with the
specified substring and then clicks on it.
https://www.javatpoint.com/selenium-interview-questions 29/30