0% found this document useful (0 votes)
60 views

Selenium Interview Question

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Selenium Interview Question

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Most Asked API Question For SDET

Before we start looking into the interview questions and answers let’s understand
quickly about Selenium along with the reasons behind the popularity of the same.
The most important fact about Selenium is that it has the highest market share in
any of the automation solutions available in the market for web automation, and
with that fact let’s start our interview preparation with Selenium questions and
answers.

What is Selenium?

Selenium is an open source umbrella project for a range of tools and libraries
aimed at supporting browser automation. It provides a playback tool for authoring
functional tests across most modern web browsers, without the need to learn a test
scripting language.

Why do we need Selenium?

Most programmers and developers who build website applications and wish to test
them every now and then use Selenium. One of the biggest advantages of Selenium,
which has made it so popular, is its flexibility. Any individual who creates web
programs can use Selenium to test the code and applications. Further, professionals
can debug and perform visual regression tests as per the requirements of the
website or code.

In most organisations, it is the job of quality analyst (QA) engineers to test web
applications by using Selenium. They are required to write scripts that can help in
maximising accuracy and test coverage to make changes in the project and maintain
the infrastructure of the test.

1. How to perform back,forward and refresh actions in selenium?


driver.navigate().back()
driver.navigate().forward()
driver.navigate().refresh()

2. What is the return type of findelements?

List of elements with similar property

3. Explain some of the strategies you have followed while using xpath?

Click here for answer

4. What will happen if no webelement is found for findelements?

It will return an empty list

5. What will happen if no webelement is found for findelement?

It will give error as :NoSuchElementException


6. How to switch frames in selenium?

Click Here For Answer

7. How to select value from dropdown in selenium?

Using select class as below


Select technology = new
Select(driver.findElement(By.xpath("//select[@id='effectTypes']")));
technology.selectByVisibleText("Drop");

8. What are the methods provided in selenium to select from dropdown?


selectByVisibleText()
selectByValue()
selectByIndex()

9. How to fetch text from UI in selenium?


gettext()
getAttribute("propertyname")

10. Explain some of the strategies to handle CAPTCHA?

Ans: Click Here For Answer

11. How to get current url,title and page source?


driver.getCurrentUrl();
driver.getTitle();
driver.getPageSource();

12. How to clear text using selenium?

clear() — method is used to clear text from the text area


driver.findElement(By.xpath(“//input[@placeholder=’Username’]”)).clear();

13. How to do Browser Initialization for all types of browsers?

• Firefox
WebDriver driver = new FirefoxDriver();
• Chrome
WebDriver driver = new ChromeDriver();
• Internet Explorer
WebDriver driver = new InternetExplorerDriver();
• Safari Driver
WebDriver driver = new SafariDriver();

14. What is page load strategy in Selenium?

Click Here For Answer

REVISION:

28. How to get all cookies and with name of the cookie?

driver.manage().getCookies();
driver.manage().getCookieNamed("APISID");

29. How to delete all cookies and with name of the cookie?

driver.manage().deleteCookieNamed("APISID");
driver.manage().deleteAllCookies();

30. How to add a cookie?

Cookie cookie1 = new Cookie("test2", "cookie2");


driver.manage().addCookie(cookie1);

***************************************
TOP 15 BDD - CUCUMBER Interview Q&A

************************************************

AUTHOR: LinkedIn P

11. How to handle alerts and popups in selenium?

• driver.switchTO().alert.accept() — to accept the alert box


• driver.switchTO().alert.dismiss() — to cancel the alert box

12. How to retrive alert pop up message in selenium?

• driver.switchTO().alert.getText() — to retrieve the alert message

13. How to send data to alert box in Selenium?

• driver.switchTO().alert.sendKeys(“Text”) — to send data to the alert box

14. How to switch frames in selenium?

• driver.switchTo.frame(int frameNumber) — mentioning the frame index number,


the Driver will switch to that specific frame
• driver.switchTo.frame(string frameNameOrID) — mentioning the frame element or
ID, the Driver will switch to that specific frame
• driver.switchTo.frame(WebElement frameElement) — mentioning the frame web
element, the Driver will switch to that specific frame

15. How to switch back to main window in frames?

• driver.switchTo().defaultContent() — Switching back to the main window


*.What are the new features in Selenium 4? VERY IMP

CLICK HERE FOR ANSWER

16. How to handle multiple windows and tabs in Selenium?

• getWindowHandle() — used to retrieve the handle of the current page (a unique


identifier)
• getWindowHandles() — used to retrieve a set of handles of the all the pages
available
17. How to switch between windows and tabs?
• driver.switchTo().window(“windowName/handle”) — switch to a window

18. How to close the cureent browser window?

• driver.close() — closes the current browser window

*. Which Source code management tool you have used and tell me some of the basic
commands that you have used?

CLICK HERE FOR ANSWER

*. Have you worked on database side for fetching data to validate in selenium
tests, if Yes then can you tell me some of the basic queries that you have used in
day to day work?

CLICK HERE FOR TOP 11 SQL QUERY

*. How to launch batch file from Selenium WebDriver?

Process batch = Runtime.getRuntime.exec("path of the batch file");

*. How to run selenium test from command line?

java -classpath ".;selenium-server-standalone-2.33.0.jar" SampleClass

*. What is the name of the super interface of the Webdriver?

Ans: SearchContext.

*. Explain some of the strategy you have followed while using xpath?

Click here for answer

19. How to handle Implicit wait?


Used to wait for a certain amount of time before throwing an exception
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

20. How to handle Explicit wait?


Used to wait until a certain condition occurs before executing the code.
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.presenceOfElementLocated(By.name("login")));

Top Interview question on Selenium Set-1 can be found below:


Selenium Interview Question SET-1
Selenium Interview Questions SET-3

21. How to read properties file and fetch data ? Code to read common.properties
file in framework?

Ans: CLICK HERE FOR CODE

*************************************************
Difference between getwindowHandle and getwindowHandles ?

ANS:
driver.getWindowHandle() return a String of alphanumeric window handle and is
mainly used to get the window handle of the current window.
driver.getWindowHandles() return a set of window handles and is mainly used to get
the window handle of all the current windows.

3. How to handle popup and alerts in selenium?

ANS:

Alert alert = driver.switchTo().alert();

alert.accept(); //it will click on "ok"


alert.dismiss(); //it will click on "cancel"

You might also like