Selenium Interview Questions and Answers
Hello Friends! this post is related to the basic Selenium Interview Questions that one should not forget to look before attending automation testing interview questions for Selenium. This article will list out 10 such basic selenium interview questions and answers.
Disclaimer : This post is related to Java Selenium Interview question and not any outher programming language.
1) What is
Selenium Webdriver?
Selenium Webdriver is a free and open source set of
APIs(Classes and Methods) used for the automation of browser's user
interface(UI). This is one of the basic selenium interview question you will get and most of the people get it wrong by answering Selenium as a tool. But it is not a tool it is an API(Application Programming Interface).
Also, try: Selenium Quiz with Answers
2) How do
you create objects of different web browsers in Selenium ?
Different web browsers in the market implement the WebDriver interface in their own way.
For creating objects of these browsers you have to assign object of the browsers to WebDriver interface.
This also helps in achieving Dynamic Polymorphism(a Java concept) i.e., you can pass the browser name at run time from some configuration files or from Testng or Jenkins.
Example :
WebDriver driver = new ChromeDriver(); //For Chrome Browser
WebDriver driver = new FirefoxDriver(); //For Firefox Browser
3) Launch
specific browser for running you Selenium Scripts?
The most important thing for running your scripts in
different browser is setting the system properties with driver executable.
You can download driver executable from the respective browser's site.
System.setProperty("driverName","executablePath"); //Syntax
System.setProperty("webdriver.chrome.driver","C://drivers/chrome.exe"); //Example
4) Finding a
WebElement in Selenium?
findElement() is used for finding a web element in Selenium Webdriver. This method is present in the WebDriver interface and takes a locator as an argument.
Locator locates an Element with the help of By class.
Suppose you have below textbox in
webpage :
<input type="text" id="username" />
Below code can be used to find
the above WebElement :
driver.findElement(locator); //Syntax
driver.findElement(By.id("username")); //Example
//username is the id of webelement
5) Different
ways of locating an element in Selenium?
Locators are basic building blocks for getting expert in Selenium. You need to know all the locators listed below to be a good Selenium Automation Tester.
Locators are basic building blocks for getting expert in Selenium. You need to know all the locators listed below to be a good Selenium Automation Tester.
There are 8 ways of locating an element in Selenium :
1. Id
2. Name
3. Class Name
4. CSS Selector
5. XPath
6. Tag Name
7. Link Text
8. Partial Link Text
The easiest technique for locating elements is by using Id. But most of the times developers generate IDs dynamically, making it of no use.
Apparently, XPath is the best technique for locating elements. You can check questions on XPath below:
Also Check this: Selenium Interview Questions - XPath
6) Difference between close() and quit() in Selenium?
close and quit are basic WebDriver commands for working with Windows in Selenium.
close(): closes the currently opened window.
quit(): closes all the opened windows.
7) Opening a
URL in Selenium?
Below code can be used for opening a URL :
driver.get("url of page"); //Syntax
driver.get("https://www.google.com"); //Example
//OR
driver.navigate().to("url of page"); //Syntax
driver.navigate().to("https://www.google.com"); //Example
8)
Difference between driver.get() and driver.navigate().to()?
driver.get() navigates to a specified URL. It refreshes the page and doesn't allow moving forward and backward in browser history.
driver.get() navigates to a specified URL. It refreshes the page and doesn't allow moving forward and backward in browser history.
driver.navigate().to() navigates to a specified URL. In SPA(Single Page Applications) it doesn't refresh the page and allows moving forward and backward in browser history.
9) Entering
text in a textbox - Selenium?
In Selenium Webdriver, sendKeys() can be used for entering text in a textbox. It is one of the methods of WebDriver interface which the other driver classes implement.
In Selenium Webdriver, sendKeys() can be used for entering text in a textbox. It is one of the methods of WebDriver interface which the other driver classes implement.
Suppose you have below textbox in webpage :
<input type="text" id="username" />
Then, you have to find the input tag and enter your text using sendkeys().
driver.findElement(By.id("username")).sendKeys("Dave"); //can be used to enter text.
10) How to
Check and Uncheck a Checkbox - Selenium?
It can be done by just clicking on the checkbox.
Suppose you have below checkbox on the webpage :
It can be done by just clicking on the checkbox.
Suppose you have below checkbox on the webpage :
<input type="checkbox" id="city" value="mumbai" />
Then,
driver.findElement(By.id("city")).click(); //can be used to check/uncheck a checkbox.
------------------------------------------------------------------------------------------
I will be posting more advanced
questions in the upcoming posts. Stay Tuned. Thanks.
Do send your comment if any
doubts!

0 Comments