Selenium Interview Questions


Here is a list of Selenium questions that will help prepare you for your next job interview.

#1

Which one of the following is not a method for locating web elements? (Choose all that apply)

A. id()
B. linkText()
C. xpath()
D. class()
E. cssSelector()
F. tagName()
G. None of the above

Answer

D

There are eight strategies to locate web elements using Selenium and they are as follows.

LocatorMethod (Java)Description
class nameclassName()Locates elements whose class name contains the search value (compound class names are not permitted)
css selectorcssSelector()Locates elements matching a CSS selector
idid()Locates elements whose ID attribute matches the search value
namename()Locates elements whose NAME attribute matches the search value
link textlinkText()Locates anchor elements whose visible text matches the search value
partial link textpartialLinkText()Locates anchor elements whose visible text contains the search value. If multiple elements are matching, only the first one will be selected.
tag nametagName()Locates elements whose tag name matches the search value
xpathxpath()Locates elements matching an XPath expression

Click here to learn more about Selenium locators.

#2

When using the Java WebDriver library, which of the following is the correct way to visit a website? (Choose all that apply)

A. driver.getUrl("https://automatenow.io/");
B. driver.goToUrl("https://automatenow.io/");
C. driver.get("https://automatenow.io/");
D. driver.navigate().to("https://automatenow.io/");
E. driver.fetchUrl("https://automatenow.io/");
F. All of the above
Answer

Coming soon!

#3

Which of the following commands notifies Selenium Grid that the browser is no longer in use so it can be used by another session? (Choose all that apply)

A. driver.endSession();
B. driver.terminateSession();
C. driver.quit();
D. driver.close(0);
E. driver.close();
Answer

C

Options A, B and D are incorrect given that they are not valid Selenium methods. Option E is only used to close a tab or window, but not the browser session. Per Selenium’s official website, calling driver.quit() does the following.

  • Closes all the windows and tabs associated with that WebDriver session.
  • Closes the browser process.
  • Closes the background driver process.
  • Notifies Selenium Grid that the browser is no longer in use so it can be used by another session (if you are using Selenium Grid).

Moreover, failure to call quit() will leave extra background processes and ports running on your machine which could cause you problems later.

#4

In Selenium 4, which command opens and switches to a new browser window?

A. driver.manage().window().new();
B. driver.manage().window().newWindow();
C. driver.switchTo().newWindow();
D. driver.switchTo().newWindow(WindowType.WINDOW);
E. None of the above
Answer

D

The command to open a new window in Selenium 4 is driver.switchTo().newWindow(WindowType.WINDOW). Click here to learn more.

#5

Which one of the following is a Relative Locator in Selenium 4? (Choose all that apply)

A. above
B. below
C. leftOf
D. rightOf
E. near
F. All of the above
Answer

A, B, E

Selenium 4’s Relative Locators include the following.

  • above
  • below
  • toLeftOf
  • toRightOf
  • near

Click here to learn more about Relative Locators.

#6

True or false, Selenium can be used to automate CAPTCHA.

Answer

False

CAPTCHA stands for the “Completely Automated Public Turing test to tell Computers and Humans Apart”. As its name implies, it is designed to prevent automation. This is why Selenium, or any other automation tool, cannot be used to automate CAPTCHA.

#7

Which one of the following is a method in the ExpectedConditions class? (Choose all that apply)

A. alertIsPresent()
B. elementToBeClickable()
C. textToBe​()
D. titleContains
E. and()
F. All of the above
Answer

Coming soon!

Leave a Reply