Selenium Interview Questions
Selenium Interview Questions
Automation testing is the process of testing the software using an automation tool to find the defects. In this
process, executing the test scripts and generating the results are performed automatically by automation
tools. Some most popular tools to do automation testing are HP QTP/UFT, Selenium WebDriver, etc.,
5. What is a Framework?
A framework defines a set of rules or best practices which we can follow in a systematic way to achieve the
desired results. There are different types of automation frameworks and the most common ones are:
• Data Driven Testing Framework
• Keyword Driven Testing Framework
• Hybrid Testing Framework
7. Can you explain the Framework which you have used in your Selenium Project?
Here we have clearly explained each component of Framework.
12. Which is the only browser that supports Selenium IDE to be used?
Firefox
In simple words, it is used to distribute your test execution on multiple platforms and environments
concurrently.
The fastest implementation of WebDriver is the HTMLUnitDriver. It is because the HTMLUnitDriver does not
execute tests in the browser.
Double Slash “//” – Double slash is used to create XPath with relative path i.e. the XPath would be created to
start selection from anywhere within the document.
28. What is the difference between Absolute Path and Relative Path?
Absolute XPath starts from the root node and ends with desired descendant element’s node. It starts with top
HTML node and ends with input node. It starts with a single forward slash(/) as shown below.
/html/body/div[3]/div[1]/form/table/tbody/tr[1]/td/input
Relative XPath starts from any node in between the HTML page to the current element’s node(last node of the
element). It starts with a single forward slash(//) as shown below.
//input[@id='email']
Verify: In simple words, there won’t be any halt in the test execution even though the verify condition is true
or false.
For detailed post check the below link.
30. What are Soft Assert and Hard Assert in Selenium?
Soft Assert: Soft Assert collects errors during @Test Soft Assert does not throw an exception when an assert
fails and would continue with the next step after the assert statement
Hard Assert: Hard Assert throws an AssertException immediately when an assert statement fails and test suite
continues with next @Test
31. What are the verification points available in Selenium?
In Selenium IDE, we use Selenese Verify and Assert Commands as Verification points
In Selenium WebDriver, there is no built-in features for verification points. It totally depends on our coding
style. some of the Verification points are
To check for page title
To check for certain text
To check for certain element (text box, button, drop down, etc.)
<2.53 – no geckodriver
3.x – geckodriver for FF
‘WebDriver‘ is an interface and we are creating an object reference of type WebDriver instantiating an object
of FirefoxDriver class.
36. We do create a reference variable ‘driver’ of type WebDriver
WebDriver driver = new FirefoxDriver();
instead of creating
FirefoxDriver driver = new FirefoxDriver();
1 WebDriver driver = new FirefoxDriver();
2
3 instead of creating
4
5 FirefoxDriver driver = new FirefoxDriver();
37. What are the different exceptions you have faced in Selenium WebDriver?
• WebDriverException
• TimeoutException
• NoAlertPresentException
• NoSuchWindowException
• NoSuchElementException
• StaleElementReferenceException
• IllegalStateException
38. How To Login Into Any Site If It Is Showing Any Authentication Pop-Up For Username And Password?
To do this we pass username and password with the URL
http://username:password@url
e.g. http://admin:[email protected]
43. How to input text in the text box using Selenium WebDriver?
By using sendKeys() method
WebDriver driver = new FirefoxDriver();
driver.get("https://www.gmail.com");
driver.findElement(By.xpath("xpath")).sendKeys("test");
44. How to input text in the text box without calling the sendKeys()?
// To initialize js object
JavascriptExecutor JS = (JavascriptExecutor)driver;
// To enter username
JS.executeScript("document.getElementById(‘User').value=test.com'");
45. How to clear the text in the text box using Selenium WebDriver?
By using clear() method
WebDriver driver = new FirefoxDriver();
driver.get("https://www.gmail.com");
driver.findElement(By.xpath("xpath_of_element1")).sendKeys("Software Testing Material Website");
driver.findElement(By.xpath("xpath_of_element1")).clear();
54. What is the alternative to driver.get() method to open an URL using Selenium WebDriver?
Alternative method to driver.get(“url”) method is driver.navigate.to(“url”)
driver.navigate().forward(); – to navigate to the next web page with reference to the browser’s history
driver.navigate().back(); – takes back to the previous webpage with reference to the browser’s history
driver.navigate().refresh(); – to refresh the current web page thereby reloading all the web elements
driver.navigate().to(“url”); – to launch a new web browser window and navigate to the specified URL
61. What are the ways to refresh a browser using Selenium WebDriver?
There are multiple ways to refresh a page in selenium
• Using driver.navigate().refresh() command as mentioned in the question 45
• Using driver.get(“URL”) on the current URL or using driver.getCurrentUrl()
• Using driver.navigate().to(“URL”) on the current URL or driver.navigate().to(driver.getCurrentUrl());
• Using sendKeys(Keys.F5) on any textbox on the webpage
62. What is the difference between driver.getWindowHandle() and driver.getWindowHandles() in Selenium
WebDriver?
dropdown.selectByVisibleText(Text);
dropdown.selectByIndex(Index);
dropdown.selectByValue(Value);
In Selenium 3, we may face few issues while capturing Screenshots. To overcome we use aShot utility. Click on
below links to see posts related to the normal way of capturing a screenshot and capturing a screenshot using
aShot utility.
73. How to find more than one web element in the list?
// To store the list
List <WebElement> eleList = driver.findElements(By.xpath("xpath"));
// To fetch the size of the list
int listSize = eleList.size();
//for loop
for (int i=0; i<listSize; i++)
{
// Clicking on each link
links.get(i).click();
// Navigating back to the previous page that stores the links
driver.navigate().back();
}
77. List some scenarios which we cannot automate using Selenium WebDriver?
1. Bitmap comparison Is not possible using Selenium WebDriver
2. Automating Captcha is not possible using Selenium WebDriver
3. We can not read bar code using Selenium WebDriver
4. windows OS based pop ups
5. third party calendars/element
6. Image
7. Word/PDF
79. How can you use the Recovery Scenario in Selenium WebDriver?
By using “Try Catch Block” within Selenium WebDriver Java tests.
try {
driver.get("www.xyz.com");
}catch(Exception e){
System.out.println(e.getMessage());
}
82. How to run Selenium WebDriver Test from the command line?
Class A{
cd c
c: javac A.java
c: java A.java
action.contextClick(driver.findElement(By.xpsjht()).build().perform();