Selenium Interview Question and Answers – Part 3

In this Article, you can find Selenium Interview question and answers – Part 2. This is in continuation of Part2.

Selenium Interview Questions and Answers

11. How to handle alerts and confirmation boxes in Selenium WebDriver?.

Selenium provides an API to handle this. Alert alert().
Below are the methods present in Alert API, which are used to handle Alerts
void accept(): This is equivalent to the OK button action on the dialog. The corresponding OK button actions are invoked when the accept() action is taken on a dialog.
void dismiss():This is equivalent to clicking on the CANCEL action button.
java.lang.S tring getText(): This will return the text that appears on the dialog. This can be used if you want to evaluate the text on the modal dialog.
void sendKeys(java.lang.S tring keysToSend): This will allow the developer to type in some text into the alert if the alert has some provision for it.

12. How to handle colours in Selenium Webdriver ?

Get the value of a given CSS property. Color values should be returned as rgba strings, so, for example if the “background-color” property is set as “green” in the HTML source, the returned value will be “rgba(0, 255, 0, 1)”.

13. How to press shift +tab in Selenium?

public class SendKeys
public static void main(String[] args)
WebDriver driver = new FirefoxDriver();
WebElement searchBox = driver.findElement("q")); searchBox.sendKeys(Keys.chord(Keys.SHIFT, "packt publishing")); }

14. How to take a screenshot in selenium?

WebDriver driver = new FirefoxDriver(); driver.get("");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere 

FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

15. Is there a way to click hidden link in Selenium WebDriver?

There is a easier way to work around the problem using JavascriptExecutor.
For example:


The above javascript would click on the “Selenium” tag on the top right of this page (next to your question), even if it were hidden.
All you need to do is issue this JS instruction via the JavascriptExecutor interface like so:


16. What are the technical challenges that you faced with selenium?

Answer to this question differ person to person. Do tell all the challenges in real which you faced.

17. What is an Xpath in Selenium?

Xpath is used to locate a web element based on its XML path. XML stands for Extensible Markup Language and is used to store, organize and transport arbitrary data. It stores data in a key-value pair which is very much similar to HTML tags. Both being markup languages and since they fall under the same umbrella, Xpath can be used to locate HTML elements.

18. How to refresh a page without using context click?

1.Using sendKeys.Keys method


2.Using navigate.refresh() method


3.Using method


4.Using get() method


5.Using sendKeys() method


19. How to handle autocomplete box in web driver?

driver.findElement("your searchBox")).sendKeys("your partial keyword"); 
List <WebElement> listItems = driver.findElements(By.xpath("your list item locator")); listItems.get(0).click();
driver.findElement("your searchButton")).click();

20. Difference between the getWindowHandle and getWindowHandles.

getWindowHandles() –  Syntax: Set getWindowHandles()
Example: driver.getWindowHandles();
Purpose: Return a set of window handles which can be used to iterate over all the open windows of this Webdriver instance  by passing them to switchTo().WebDriver.Options.window() Returns: A set of window handles which can be used to iterate over all the open windows.

getWindowHandle() – Syntax: String getWindowHandle()
Example: driver.getWindowHandle();
Parameter: Return an opaque handle to this window that uniquely identifies it within this driver instance. This can be used to switch to this window at a later date.


Refer below posts for next interview questions –

Selenium Interview Questions and Answers – Part 1

Selenium Interview Question and Answers – Part 3

Selenium Interview Question and Answers – Part 4

Selenium Interview Question and Answers – Part 5

Leave Comment

Your email address will not be published. Required fields are marked *

Looking for learning Framework Development from Scratch? Lookout for Detailed Framework Development videos on YouTube here -

Get the Framework code at Github Repo: