Selenium Interview Questions and Answers
Intermediate / 1 to 5 years experienced level questions & answers
Ques 1. What do you mean by XPath?
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 is a language used for locating nodes in XML documents.
- 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 provides locating strategies like:
- XPath Absolute
- XPath Attributes
Ques 2. Explain XPath Absolute and XPath attributes.
XPath Absolute:
- XPath Absolute enables users to mention the complete XPath location from the root HTML tag to the specific elements.
- 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.
- Syntax: //htmltag[@attribute1='value1' and @attribute2='value2']
- Example: //input[@id='passwd' and @placeholder='password']
Ques 3. What is the difference between "type" and "typeAndWait" command?
"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.
Ques 4. What is the difference between findElement() and findElements()?
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.
Ques 5. What is the wait? How many types of waits in selenium?
Selenium Webdriver introduces the concept of waits for the AJAX-based application. There are two types of waits:
- Implicit Wait
- Explicit Wait
Ques 6. What is the main disadvantage of implicit wait?
The main disadvantage of implicit wait is that it slows down test performance.
Another disadvantage of implicit wait is:
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.
Ques 7. What is Selenium Grid?
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.
Ques 8. How can we launch different browsers in Selenium WebDriver?
We have to create an instance of a driver of that particular browser.
WebDriver driver =newFirefoxDriver();
Here, "WebDriver" is an interface, and we are creating a reference variable "driver" of type WebDriver, instantiated using "FireFoxDriver" class.
Ques 9. Write a code snippet to launch Firefox browser in WebDriver.
public class FirefoxBrowserLaunchDemo {
public static void main(String[] args) {
//Creating a driver object referencing WebDriver interface
WebDriver driver;
//Setting webdriver.gecko.driver property
System.setProperty("webdriver.gecko.driver", pathToGeckoDriver + "\\geckodriver.exe");
//Instantiating driver object and launching browser
driver = newFirefoxDriver();
//Using get() method to open a webpage
driver.get("http://javatpoint.com");
//Closing the browser
driver.quit();
}
}
Ques 10. Write a code snippet to launch Chrome browser in WebDriver.
public class ChromeBrowserLaunchDemo {
public static void main(String[] args) {
//Creating a driver object referencing WebDriver interface
WebDriver driver;
//Setting the webdriver.chrome.driver property to its executable's location
System.setProperty("webdriver.chrome.driver", "/lib/chromeDriver/chromedriver.exe");
//Instantiating driver object
driver = newChromeDriver();
//Using get() method to open a webpage
driver.get("http://javatpoint.com");
//Closing the browser
driver.quit();
}
}
Ques 11. Write a code snippet to launch Internet Explorer browser in WebDriver.
public class IEBrowserLaunchDemo {
public static void main(String[] args) {
//Creating a driver object referencing WebDriver interface
WebDriver driver;
//Setting the webdriver.ie.driver property to its executable's location
System.setProperty("webdriver.ie.driver", "/lib/IEDriverServer/IEDriverServer.exe");
//Instantiating driver object
driver = newInternetExplorerDriver();
//Using get() method to open a webpage
driver.get("http://javatpoint.com");
//Closing the browser
driver.quit();
}
}
Most helpful rated by users:
Related interview subjects
ETL Testing interview questions and answers - Total 20 questions |
QTP interview questions and answers - Total 44 questions |
Cucumber interview questions and answers - Total 30 questions |
Postman interview questions and answers - Total 30 questions |
TestNG interview questions and answers - Total 38 questions |
SDET interview questions and answers - Total 30 questions |
Selenium interview questions and answers - Total 40 questions |
Kali Linux interview questions and answers - Total 29 questions |
Mobile Testing interview questions and answers - Total 30 questions |
UiPath interview questions and answers - Total 38 questions |
Quality Assurance interview questions and answers - Total 56 questions |
API Testing interview questions and answers - Total 30 questions |
Appium interview questions and answers - Total 30 questions |