SlideShare a Scribd company logo
2
Most read
4
Most read
5
Most read
1/6
By Varsha July 2, 2021
Latest Selenium Interview Questions And Answers
automationqahub.com/latest-selenium-interview-questions-and-answers/
1)What is the difference between selenium 3 and selenium 4.
Selenium 3 uses the JSON wire protocol and selenium 4 uses W3C
standardization.
 Native Support was removed for browsers like Opera and PhantomJs in selenium
4.
Selenium IDE was only available as a Firefox extension in version 3. However, in
selenium version 4 IDE is available for Chrome as well.
Unlike selenium 3, Selenium 4 provides native support for chrome DevTools.
Selenium 4 has introduced Relative locators that allow testers to find elements
relative to another element in DOM.
Docker support has been added to the Grid server for more efficient parallel
execution.
2) Which selenium web driver locator should be preferred?
ID is the preferred choice because it is less prone to changes, However, CSS is
considered to be faster and is usually easy to read. XPath can walk up and down the
DOM, which makes Xpath more customizable.
3)Explain difference between findElement() and find elements().
findElement(): This command is used for finding a particular element on a web
page, it is used to return an object of the first found element by the locator. Throws
NoSuchElementException if the element is not found.
find elements(): This command is used for finding all the elements in a web page
specified by the locator value. The return type of this command is the list of all the
matching web elements. It returns an empty list if no matching element is found.
4)Explain the difference between Thread.Sleep() and selenium.setSpeed().
Thread.Sleep(): It causes the current thread to suspend execution for a specified
period.
selenium.setSpeed():setSpeed sets a speed that will apply a delay time before
every Selenium operation.
5)How to handle stale element reference exception?
The stale element exception occurs when the element is destroyed and recreated again
in DOM. When this happens the reference of the element in DOM becomes stale. This
can be handled in numerous ways.
2/6
1)Refresh the page and try to locate the stale element again.
2) Use Explicit wait to ignore the stale element exception.


3) Try to access the element several times in the loop(Usually not recommended.)
6)How many types of WebDriver APIs are available in selenium.
Chrome, Geko Driver, Chromium, Edge.
7)How to open the browser in incognito mode.
This can be done by using ChromeOptions class to customize the chrome driver session
and adding the argument as “incognito”.
ChromeOptions options = new ChromeOptions(); options.addArguments(“–
incognito”); DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
8)How to handle file upload in selenium.
File upload can be done in 3 ways:
By using Robot class.
By using sendkeys.
By using AutoIt.
9)How many parameters are selenium required?
Selenium requires four parameters:
Host
Port Number
Browser
URL
10)How to retrieve css properties of an element.
driver.findElement(By.id(“id“)).getCssValue(“name of css attribute”);


driver.findElement(By.id(“id“)).getCssValue(“font-size”); 
11)How can you use the Recovery Scenario in Selenium WebDriver?
By using “Try Catch Block” within Selenium WebDriver Java tests.
12)How To Highlight Element Using Selenium WebDriver?
Use Javascript Executor interface:
JavascriptExecutor js = (JavascriptExecutor) driver;

js.executeScript("arguments[0].setAttribute('style', 'background: yellow; border:
2px solid red;');", element);
3/6
13)Explain a few advantages of the Page Object Model.
Readable and Maintainable code.
Less and optimized code.
Low redundancy.
14)List some Commonly used interfaces of selenium web driver.
WebDriver
TakesScreenshot
JavascriptExecutor
WebElement
SearchContext
15)What is the difference between @FindAll and @Findbys.
@FindBys: When the required WebElement objects need to match all of the given
criteria use @FindBys annotation.
@FindBys( {

@FindBy(className = "class1")

@FindBy(className = "class2")

} )
private List<WebElement> ele //elements With Both_class1 AND class2;
@FindAll: When required WebElement objects need to match at least one of the given
criteria use the @FindAll annotation.
@FindAll({

@FindBy(className = "class1")

@FindBy(className = "class2")

})
private List<WebElement> ele //elements With Either_class1 OR class2 ;
16)How to Click on a web element if the selenium click() command is not
working.
There are multiple ways provided by the selenium web driver to perform click operations.
You can use either Action class or can leverage javascript executor.
a) Javascript executor is an interface provided by selenium to run javascript through
selenium web driver.
import org.openqa.selenium.JavascriptExecutor;

public void clickThruJS(WebElement element) {

JavascriptExecutor executor = (JavascriptExecutor) Driver;

executor.executeScript(“arguments[0].click();”, element);

}
4/6
b) Action class is provided by selenium to handle mouse and keyboard interactions.
import org.openqa.selenium.interactions.Actions;

public void ClickToElement(WebElement elementName) {

Actions actions = new Actions(Driver);

actions.moveToElement(elementName).perform();

actions.moveToElement(elementName).click().perform();

}
17)How to exclude a test method from execution in TestNG.
By adding the exclude tag in the testng.xml file.
<classes> 

<class name=”TestCaseName”> 

<methods>

<exclude name=”TestMethodName”/>

</methods>

</class>

</classes>
18)What are different ways of ignoring a test from execution.
Making parameter “enabled” as “false”.
Using the “exclude” parameter in testng.xml.
“throw new SkipException()” in the if condition to Skip / Ignore Test.
19)What is the difference between scenario and scenario outline in
cucumber?
When we want to execute a test one time then we use the scenario keyword. If we want
to execute a test multiple times with different sets of data then we use the scenario outline
keyword. A scenario outline is used for data-driven testing or parametrization. We use
example keywords to provide data to the scenario outline
20)What are different ways to reload a webpage in selenium?
1)Driver.navigate().refresh()


2)Driver.get(Driver.getCurrentUrl())


3)Driver. findElement(By.id(“id”)).sendKeys(Keys.F5);


4)Driver.navigate().to(Driver.getCurrentUrl())
21)What is the difference between getText() and getAttribute().
getText() method returns the text present which is visible on the page by ignoring the
leading and trailing spaces, while the getAttribute() method returns the value of the
attribute defined in the HTML tag.
22)How to disable Chrome notifications using selenium?
You need to use chrome options to disable notifications on chrome:
5/6
Map<String, Object> prefs = new HashMap<String, Object>();

prefs.put("profile.default_content_setting_values.notifications", 2);

ChromeOptions options = new ChromeOptions();

options.setExperimentalOption("prefs", prefs);

WebDriver driver = new ChromeDriver(options);
23)What is the difference between @BeforeTest and @BeforeMethod?
@BeforeTest will run only once before each test tag defined in testng.xml, however,
@BeforeMethod will run before every method annotated with the @Test tag. In other
words, every test in a file is a method but vice versa is not true, so no matter how many
methods are annotated with @Test, @BeforeTest will be called only one time and
@BeforeMethod executes before each test method.
24)Explain cucumberOptions with the keywords.
@CucumberOptions enables us to define some settings for our tests, it works like the
cucumber JVM command line. Using @CucumberOptions we can define the path of the
feature file and the step definition file, we can also use other keywords to set our test
execution properly.
25)What is cucumber DryRun?
Dry Run is used to check the complete implementation of all the mentioned steps present
in the Feature file. If it is set as true, then Cucumber will check that every Step mentioned
in the Feature File has corresponding code written in the Step Definition file or not.
26)How to set the Priority of cucumber Hooks?
@Before(order = int) : This runs in incremental order, like (order=0) will execute first
then (order=1) and so on.
@After(order = int): This executes in decremental order, which means value 1 would run
first and 0 would be after 1.
27)What is a data table in cucumber and how to use it?
Data tables are used when the scenario step requires to be tested with multiple input
parameters, multiple rows of data can be passed in the same step and it’s much easier to
read.
Scenario: Valid Registration Form Information 

Given User submits a valid registration form

| John | Doe |01-01-1990 |999999999 |

Then System proceeds with registration
28)Explain invocation count in testNg.
6/6
invocation count: It refers to the number of times a method should be invoked. It
will work as a loop. Eg: @Test(invocation count = 7) . Hence, this method will
execute 7 times.
29)Explain build().perform() in actions class.
build()  This method in the Actions class is used to create a chain of action or
operation you want to perform.
perform()  This method is used toexecute a chain of actions that are built using the
Action build method.
30)What is the difference between driver.close() and driver.quit()?
driver. close(): Close the browser window which is currently in focus and make session-id
invalid or expires.
driver.quit(): Closes all the browser windows and terminates the web driver session.
Session-id becomes null.
31)What are the locator strategies in Selenium.
Traditional Locators
Id, Name, ClassName, TagName, Link text, Partial LinkText, Xpath, CSS Selector.
Relative Locators
above, below, Left of, Right Of, Near
Locators can also be chained as per the latest Selenium 4 Release.
By submitLocator =
RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("c

More Related Content

PDF
Automation testing real time interview question.pdf
PDF
Selenium Webdriver Interview Questions
PDF
Selenium interview questions and answers
PDF
Selenium Automation Testing Interview Questions And Answers
PPTX
Dev labs alliance top 50 selenium interview questions for SDET
PDF
Interview Question & Answers for Selenium Freshers | LearningSlot
PPTX
Selenium-Locators
PDF
Page Object Model and Implementation in Selenium
Automation testing real time interview question.pdf
Selenium Webdriver Interview Questions
Selenium interview questions and answers
Selenium Automation Testing Interview Questions And Answers
Dev labs alliance top 50 selenium interview questions for SDET
Interview Question & Answers for Selenium Freshers | LearningSlot
Selenium-Locators
Page Object Model and Implementation in Selenium

What's hot (20)

DOCX
Selenium interview-questions-freshers
PPTX
Test automation using selenium
PPTX
Cucumber BDD
PPTX
Spring MVC
PDF
테스트자동화 성공전략
DOCX
Selenium interview questions
PDF
Xpath in Selenium | Selenium Xpath Tutorial | Selenium Xpath Examples | Selen...
PPT
Selenium
PDF
Interview question & Answers for 3+ years experienced in Selenium | LearningSlot
PDF
An introduction to React.js
PPTX
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
PDF
PDF
TestNG Annotations in Selenium | Edureka
PPTX
React js
PPTX
Automation - web testing with selenium
PPTX
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
PPTX
What Is Virtual DOM In React JS.pptx
PDF
Java 8 Lambda Expressions & Streams
PPTX
Understanding react hooks
PPTX
Selenium WebDriver training
Selenium interview-questions-freshers
Test automation using selenium
Cucumber BDD
Spring MVC
테스트자동화 성공전략
Selenium interview questions
Xpath in Selenium | Selenium Xpath Tutorial | Selenium Xpath Examples | Selen...
Selenium
Interview question & Answers for 3+ years experienced in Selenium | LearningSlot
An introduction to React.js
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
TestNG Annotations in Selenium | Edureka
React js
Automation - web testing with selenium
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
What Is Virtual DOM In React JS.pptx
Java 8 Lambda Expressions & Streams
Understanding react hooks
Selenium WebDriver training
Ad

Similar to Latest Selenium Interview Questions And Answers.pdf (20)

PDF
Top 15 Selenium WebDriver Interview Questions and Answers.pdf
PPTX
Top 30 Selenium Interview Questions.pptx
PDF
Top 25 Selenium Interview Questions and Answers 2018
DOCX
Selenium WebDriver FAQ's
PDF
selenium-webdriver-interview-questions.pdf
PDF
25 Top Selenium Interview Questions and Answers for 2023.pdf
PPTX
DevLabs Alliance Top 50 Selenium Interview Questions for SDET
PPTX
DevLabs Alliance Top 50 Selenium Interview Questions for SDET
PDF
Selenium webdriver interview questions and answers
DOCX
Experienced Selenium Interview questions
PDF
Selenium Interview Questions and Answers For Freshers And Experienced | Edureka
PDF
Top 21 Selenium FAQs.pdf
PPT
4.1 Selenium_Course_Content.ppt
PPT
Selenium_Course_Contenttttttttttttttttt.ppt
PPT
Selenium-Course-Content.ppt
PDF
Selenium for Tester.pdf
PPTX
Selenium.pptx
DOCX
Selenium interview Q&A
PPTX
Selenium web driver
PDF
Selenium Introduction by Sandeep Sharda
Top 15 Selenium WebDriver Interview Questions and Answers.pdf
Top 30 Selenium Interview Questions.pptx
Top 25 Selenium Interview Questions and Answers 2018
Selenium WebDriver FAQ's
selenium-webdriver-interview-questions.pdf
25 Top Selenium Interview Questions and Answers for 2023.pdf
DevLabs Alliance Top 50 Selenium Interview Questions for SDET
DevLabs Alliance Top 50 Selenium Interview Questions for SDET
Selenium webdriver interview questions and answers
Experienced Selenium Interview questions
Selenium Interview Questions and Answers For Freshers And Experienced | Edureka
Top 21 Selenium FAQs.pdf
4.1 Selenium_Course_Content.ppt
Selenium_Course_Contenttttttttttttttttt.ppt
Selenium-Course-Content.ppt
Selenium for Tester.pdf
Selenium.pptx
Selenium interview Q&A
Selenium web driver
Selenium Introduction by Sandeep Sharda
Ad

Recently uploaded (20)

PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Machine Learning_overview_presentation.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
MIND Revenue Release Quarter 2 2025 Press Release
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Accuracy of neural networks in brain wave diagnosis of schizophrenia
MYSQL Presentation for SQL database connectivity
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Digital-Transformation-Roadmap-for-Companies.pptx
Unlocking AI with Model Context Protocol (MCP)
Mobile App Security Testing_ A Comprehensive Guide.pdf
Group 1 Presentation -Planning and Decision Making .pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
NewMind AI Weekly Chronicles - August'25-Week II
Diabetes mellitus diagnosis method based random forest with bat algorithm
Spectral efficient network and resource selection model in 5G networks
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Machine Learning_overview_presentation.pptx
Empathic Computing: Creating Shared Understanding
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
MIND Revenue Release Quarter 2 2025 Press Release

Latest Selenium Interview Questions And Answers.pdf

  • 1. 1/6 By Varsha July 2, 2021 Latest Selenium Interview Questions And Answers automationqahub.com/latest-selenium-interview-questions-and-answers/ 1)What is the difference between selenium 3 and selenium 4. Selenium 3 uses the JSON wire protocol and selenium 4 uses W3C standardization.  Native Support was removed for browsers like Opera and PhantomJs in selenium 4. Selenium IDE was only available as a Firefox extension in version 3. However, in selenium version 4 IDE is available for Chrome as well. Unlike selenium 3, Selenium 4 provides native support for chrome DevTools. Selenium 4 has introduced Relative locators that allow testers to find elements relative to another element in DOM. Docker support has been added to the Grid server for more efficient parallel execution. 2) Which selenium web driver locator should be preferred? ID is the preferred choice because it is less prone to changes, However, CSS is considered to be faster and is usually easy to read. XPath can walk up and down the DOM, which makes Xpath more customizable. 3)Explain difference between findElement() and find elements(). findElement(): This command is used for finding a particular element on a web page, it is used to return an object of the first found element by the locator. Throws NoSuchElementException if the element is not found. find elements(): This command is used for finding all the elements in a web page specified by the locator value. The return type of this command is the list of all the matching web elements. It returns an empty list if no matching element is found. 4)Explain the difference between Thread.Sleep() and selenium.setSpeed(). Thread.Sleep(): It causes the current thread to suspend execution for a specified period. selenium.setSpeed():setSpeed sets a speed that will apply a delay time before every Selenium operation. 5)How to handle stale element reference exception? The stale element exception occurs when the element is destroyed and recreated again in DOM. When this happens the reference of the element in DOM becomes stale. This can be handled in numerous ways.
  • 2. 2/6 1)Refresh the page and try to locate the stale element again. 2) Use Explicit wait to ignore the stale element exception. 3) Try to access the element several times in the loop(Usually not recommended.) 6)How many types of WebDriver APIs are available in selenium. Chrome, Geko Driver, Chromium, Edge. 7)How to open the browser in incognito mode. This can be done by using ChromeOptions class to customize the chrome driver session and adding the argument as “incognito”. ChromeOptions options = new ChromeOptions(); options.addArguments(“– incognito”); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, options); 8)How to handle file upload in selenium. File upload can be done in 3 ways: By using Robot class. By using sendkeys. By using AutoIt. 9)How many parameters are selenium required? Selenium requires four parameters: Host Port Number Browser URL 10)How to retrieve css properties of an element. driver.findElement(By.id(“id“)).getCssValue(“name of css attribute”); driver.findElement(By.id(“id“)).getCssValue(“font-size”);  11)How can you use the Recovery Scenario in Selenium WebDriver? By using “Try Catch Block” within Selenium WebDriver Java tests. 12)How To Highlight Element Using Selenium WebDriver? Use Javascript Executor interface: JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("arguments[0].setAttribute('style', 'background: yellow; border: 2px solid red;');", element);
  • 3. 3/6 13)Explain a few advantages of the Page Object Model. Readable and Maintainable code. Less and optimized code. Low redundancy. 14)List some Commonly used interfaces of selenium web driver. WebDriver TakesScreenshot JavascriptExecutor WebElement SearchContext 15)What is the difference between @FindAll and @Findbys. @FindBys: When the required WebElement objects need to match all of the given criteria use @FindBys annotation. @FindBys( { @FindBy(className = "class1") @FindBy(className = "class2") } ) private List<WebElement> ele //elements With Both_class1 AND class2; @FindAll: When required WebElement objects need to match at least one of the given criteria use the @FindAll annotation. @FindAll({ @FindBy(className = "class1") @FindBy(className = "class2") }) private List<WebElement> ele //elements With Either_class1 OR class2 ; 16)How to Click on a web element if the selenium click() command is not working. There are multiple ways provided by the selenium web driver to perform click operations. You can use either Action class or can leverage javascript executor. a) Javascript executor is an interface provided by selenium to run javascript through selenium web driver. import org.openqa.selenium.JavascriptExecutor; public void clickThruJS(WebElement element) { JavascriptExecutor executor = (JavascriptExecutor) Driver; executor.executeScript(“arguments[0].click();”, element); }
  • 4. 4/6 b) Action class is provided by selenium to handle mouse and keyboard interactions. import org.openqa.selenium.interactions.Actions; public void ClickToElement(WebElement elementName) { Actions actions = new Actions(Driver); actions.moveToElement(elementName).perform(); actions.moveToElement(elementName).click().perform(); } 17)How to exclude a test method from execution in TestNG. By adding the exclude tag in the testng.xml file. <classes> <class name=”TestCaseName”> <methods> <exclude name=”TestMethodName”/> </methods> </class> </classes> 18)What are different ways of ignoring a test from execution. Making parameter “enabled” as “false”. Using the “exclude” parameter in testng.xml. “throw new SkipException()” in the if condition to Skip / Ignore Test. 19)What is the difference between scenario and scenario outline in cucumber? When we want to execute a test one time then we use the scenario keyword. If we want to execute a test multiple times with different sets of data then we use the scenario outline keyword. A scenario outline is used for data-driven testing or parametrization. We use example keywords to provide data to the scenario outline 20)What are different ways to reload a webpage in selenium? 1)Driver.navigate().refresh() 2)Driver.get(Driver.getCurrentUrl()) 3)Driver. findElement(By.id(“id”)).sendKeys(Keys.F5); 4)Driver.navigate().to(Driver.getCurrentUrl()) 21)What is the difference between getText() and getAttribute(). getText() method returns the text present which is visible on the page by ignoring the leading and trailing spaces, while the getAttribute() method returns the value of the attribute defined in the HTML tag. 22)How to disable Chrome notifications using selenium? You need to use chrome options to disable notifications on chrome:
  • 5. 5/6 Map<String, Object> prefs = new HashMap<String, Object>(); prefs.put("profile.default_content_setting_values.notifications", 2); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("prefs", prefs); WebDriver driver = new ChromeDriver(options); 23)What is the difference between @BeforeTest and @BeforeMethod? @BeforeTest will run only once before each test tag defined in testng.xml, however, @BeforeMethod will run before every method annotated with the @Test tag. In other words, every test in a file is a method but vice versa is not true, so no matter how many methods are annotated with @Test, @BeforeTest will be called only one time and @BeforeMethod executes before each test method. 24)Explain cucumberOptions with the keywords. @CucumberOptions enables us to define some settings for our tests, it works like the cucumber JVM command line. Using @CucumberOptions we can define the path of the feature file and the step definition file, we can also use other keywords to set our test execution properly. 25)What is cucumber DryRun? Dry Run is used to check the complete implementation of all the mentioned steps present in the Feature file. If it is set as true, then Cucumber will check that every Step mentioned in the Feature File has corresponding code written in the Step Definition file or not. 26)How to set the Priority of cucumber Hooks? @Before(order = int) : This runs in incremental order, like (order=0) will execute first then (order=1) and so on. @After(order = int): This executes in decremental order, which means value 1 would run first and 0 would be after 1. 27)What is a data table in cucumber and how to use it? Data tables are used when the scenario step requires to be tested with multiple input parameters, multiple rows of data can be passed in the same step and it’s much easier to read. Scenario: Valid Registration Form Information Given User submits a valid registration form | John | Doe |01-01-1990 |999999999 | Then System proceeds with registration 28)Explain invocation count in testNg.
  • 6. 6/6 invocation count: It refers to the number of times a method should be invoked. It will work as a loop. Eg: @Test(invocation count = 7) . Hence, this method will execute 7 times. 29)Explain build().perform() in actions class. build()  This method in the Actions class is used to create a chain of action or operation you want to perform. perform()  This method is used toexecute a chain of actions that are built using the Action build method. 30)What is the difference between driver.close() and driver.quit()? driver. close(): Close the browser window which is currently in focus and make session-id invalid or expires. driver.quit(): Closes all the browser windows and terminates the web driver session. Session-id becomes null. 31)What are the locator strategies in Selenium. Traditional Locators Id, Name, ClassName, TagName, Link text, Partial LinkText, Xpath, CSS Selector. Relative Locators above, below, Left of, Right Of, Near Locators can also be chained as per the latest Selenium 4 Release. By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("c