Selenium Automation
20+ Selenium Automation Interview Questions and Answers
Q1. Write a program to remove duplicate character in a string if there are multiple users in an application, and if the buttons in the applications are specific to particular user, you need to perform operation in ...
read moreQuestions related to Selenium Automation and software testing
To remove duplicate characters in a string, use a loop and a hashset
To perform operations on specific buttons for a user, use conditional statements
To switch to a particular tab, use the window handle
500 error code in Postman validation indicates a bad request
Primary key is a unique identifier for a record in a database
Roles and responsibilities in a project depend on the project and team
Q2. In a page there are two login button available, So will it have same ID?
No, the two login buttons will not have the same ID.
Each element on a web page should have a unique ID
Having two login buttons with the same ID would violate this principle
To interact with each button separately, you need to identify them using different attributes like class, name, or XPath
Q3. How will you retrieve all the values from the drop down?
To retrieve all values from a drop down, we can use the getOptions() method and store the values in an array of strings.
Locate the drop down element using any of the locators
Create a Select class object by passing the drop down element as a parameter
Use the getOptions() method to retrieve all the options from the drop down
Store the options in an array of strings
Q4. How to write the step execution report/result in the report?
Use TestNG or JUnit framework to generate step execution report/result.
Use TestNG or JUnit annotations to mark the start and end of each test step.
Use TestNG or JUnit listeners to capture the test results and generate the report.
Use reporting libraries like ExtentReports or ReportNG to generate detailed reports with screenshots and logs.
Q5. How to execute feature file in parallel in BDD Cucumber Framework
To execute feature files in parallel in BDD Cucumber Framework, we can use tools like Maven Surefire plugin or Cucumber-JVM-Parallel-Plugin.
Use Maven Surefire plugin to run tests in parallel by adding
and tags in pom.xml file Use Cucumber-JVM-Parallel-Plugin to run tests in parallel by adding @CucumberOptions(plugin = {"json:target/cucumber-report/cucumber.json", "com.github.temyers:cucumber-jvm-parallel-plugin:5.0.0"}, threads = 3) annotation in the runner class
Ensure that ...read more
Q6. How to switch to the second window using page Title?
To switch to the second window using page title, we can use getWindowHandles() and switchTo() methods.
Use getWindowHandles() method to get all the window handles
Iterate through the window handles and switch to the desired window using switchTo() method
Use getTitle() method to get the title of each window and compare it with the desired title
Share interview questions and help millions of jobseekers 🌟
Q7. Types of xpaths, project structure, cucumber dry run option, testing basic annotations, difference between interface and abstract class, what are the concepts of oops
Answering questions related to Selenium Automation
Types of xpaths: Absolute and Relative
Project structure: Follows a modular approach
Cucumber dry run option: Used to check feature file syntax
Testing basic annotations: @Test, @BeforeTest, @AfterTest
Difference between interface and abstract class: Interface has only method declarations, abstract class has both method declarations and implementations
Concepts of OOPS: Inheritance, Polymorphism, Encapsulation, Abstraction
Q8. How to get all the options in a DropDown?
To get all options in a dropdown, use the getOptions() method and store the values in an array of strings.
Locate the dropdown element using any of the locators
Create a Select class object by passing the dropdown element as a parameter
Use the getOptions() method to get all the options in the dropdown
Store the options in an array of strings
Selenium Automation Jobs
Q9. How to handle Multiple popups in selenium?
To handle multiple popups in Selenium, we can use getWindowHandles() and switchTo() methods.
Use getWindowHandles() method to get all the window handles
Switch to the desired window using switchTo() method
Perform actions on the popup window
Switch back to the main window using switchTo() method
Q10. What are the collections used in framework?
Collections like ArrayList, HashMap, HashSet are commonly used in Selenium framework.
ArrayList is used to store a list of elements
HashMap is used to store key-value pairs
HashSet is used to store unique elements
Collections class is used for sorting and searching
Q11. What is mother of all classes?
There is no such thing as 'mother of all classes' in Selenium Automation.
There is no concept of 'mother of all classes' in Selenium Automation.
It is possible that the interviewer is asking a trick question or trying to test the candidate's knowledge.
The candidate should politely ask for clarification or context before attempting to answer.
If the interviewer insists on an answer, the candidate can explain that there is no such thing and provide examples of important classes in...read more
Q12. Difference between simple Java program and maven project
A simple Java program is a standalone program while a Maven project is a build automation tool.
A simple Java program is compiled and executed using the command line or an IDE.
A Maven project uses a pom.xml file to manage dependencies and build the project.
A simple Java program may require manual management of dependencies.
A Maven project can easily manage dependencies and build the project with a single command.
A simple Java program may not have a defined project structure.
A ...read more
Q13. How to send credentials via URL?
Credentials can be sent via URL by appending them to the URL as query parameters.
Append the username and password as query parameters to the URL
Encode the username and password using Base64 encoding
Example: http://example.com/login?username=admin&password=encoded_password
Q14. How to Scroll page to desired ocation?
To scroll page to desired location, use JavaScriptExecutor and scrollTo() method.
Create an instance of JavaScriptExecutor
Use executeScript() method to execute scrollTo() method
Pass the desired location as arguments to scrollTo() method
Example: ((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight)");
Q15. Difference between Explicit wait and Fluent Wait?
Explicit wait waits for a specific condition while Fluent wait waits for a condition with polling interval.
Explicit wait waits for a specific condition to occur before proceeding further
Fluent wait waits for a condition with a polling interval and ignores exceptions
Explicit wait is used when we know the condition and the maximum time to wait for it
Fluent wait is used when we don't know the maximum time to wait for a condition
Example of explicit wait: WebDriverWait wait = new ...read more
Q16. how to initialize chrome driver?
To initialize Chrome driver, create an instance of ChromeDriver class.
Create an instance of ChromeDriver class
Set the path of ChromeDriver executable file
Use the instance to interact with the browser
Q17. What is webdriver and webelement
WebDriver is a tool for automating web applications. WebElement is an interface representing an HTML element.
WebDriver is a browser automation tool used to control the browser and interact with web elements
WebElement is an interface representing an HTML element on a web page
WebDriver interacts with web elements using the WebElement interface
Examples of web elements include buttons, text fields, and links
Q18. Why do tags used in cucumber
Tags are used in Cucumber to organize and filter scenarios and features.
Tags allow for easy organization of scenarios and features based on their purpose or functionality.
Tags can be used to filter which scenarios or features are run during a test.
Tags can be added to scenarios or features using the '@' symbol followed by the tag name.
Tags can also be used to pass parameters to step definitions.
Examples: @smoke, @regression, @login, @api, etc.
Q19. What are constructors?
Constructors are special methods that are used to initialize objects in a class.
Constructors have the same name as the class.
They are called automatically when an object is created.
They can be used to set default values for object properties.
Constructors can be overloaded to accept different parameters.
Example: public class Car { public Car() { // constructor code here } }
Q20. How to disable test.
To disable a test, we can comment out the test code or use testNG annotations.
Comment out the test code
Use testNG annotations like @Test(enabled=false)
Use testNG XML file to disable the test
Use groups to disable a set of tests
Q21. Difference between TestNg and junit
TestNG is more advanced and flexible than JUnit, with features like parallel testing and data-driven testing.
TestNG supports parallel testing while JUnit does not.
TestNG allows for data-driven testing while JUnit does not.
TestNG has more advanced annotations and reporting features than JUnit.
TestNG can be used with both Java and non-Java languages while JUnit is only for Java.
JUnit is simpler and easier to learn than TestNG.
Q22. Super interface in web driver
A super interface in Selenium WebDriver is an interface that extends multiple interfaces.
A super interface allows a class to inherit methods and variables from multiple interfaces.
It provides a way to achieve multiple inheritance in Java.
For example, the WebDriver interface is a super interface that extends multiple interfaces like SearchContext and TakesScreenshot.
Q23. Expected conditions in selenium
Expected conditions are pre-defined conditions that can be used to wait for a certain state or element in Selenium.
ExpectedConditions.elementToBeClickable() - waits for an element to be clickable
ExpectedConditions.visibilityOfElementLocated() - waits for an element to be visible
ExpectedConditions.titleContains() - waits for the page title to contain a certain text
Q24. Reporting tools in web driver
There are several reporting tools available for Selenium WebDriver.
TestNG
JUnit
ExtentReports
Allure Reports
Custom reporting using log4j or Apache log4j
Q25. Types of locators
Locators are used in Selenium Automation to identify elements on a web page.
ID Locator: Uses the 'id' attribute of an element
Name Locator: Uses the 'name' attribute of an element
Class Name Locator: Uses the 'class' attribute of an element
Tag Name Locator: Uses the HTML tag name of an element
Link Text Locator: Uses the text of a link element
Partial Link Text Locator: Uses a partial text of a link element
CSS Selector Locator: Uses CSS selectors to identify elements
XPath Locator...read more
Q26. Wait for file loading
To wait for file loading in Selenium Automation, we can use explicit wait or thread.sleep() method.
Explicit wait is used to wait for a specific condition to occur before proceeding with the next step.
Thread.sleep() method is used to pause the execution for a specified amount of time.
We can also use the ExpectedConditions class to wait for a file to be loaded.
Waiting for a file to be loaded is important to ensure that the file is available for further processing.
Q27. Priority in TestNg
Priority in TestNG determines the order in which test methods are executed.
Priority can be set using the 'priority' attribute in @Test annotation
Default priority is 0, higher priority is executed first
Priority can be negative as well
If two methods have the same priority, they are executed in alphabetical order
Q28. Types of waits
Waits are used to synchronize the test execution with the application's response.
Implicit Wait
Explicit Wait
Fluent Wait
Thread.sleep()
WebDriverWait
Top Interview Questions for Selenium Automation Related Skills
Interview experiences of popular companies
Calculate your in-hand salary
Confused about how your in-hand salary is calculated? Enter your annual salary (CTC) and get your in-hand salary
Reviews
Interviews
Salaries
Users/Month