Are you preparing for an Automation interview? then you must have basic knowledge about java and Selenium webdriver. Selenium web driver contains many methods to perform automation. I am going to share some important Interview questions and answer for the selenium web driver.

In Selenium webdriver, Which command takes you forward by one page on the browser’s history?

a) navigate.forward()

b) Navigate.forward()

c) navigate().forward()

d) Navigate.forward

e) navigate_forward()

In Seleniun webdriver, which of the following commands retrieves the text of HTML element?

a) selectText()

b) getText()

c) getElementText()

d) getText(WebElement)

Which of the following is the correct ‘Webdriver’ command to “delete all cookies in the browser”?

a) Driver.deleteAllCookies()

b) Driver.manage().deleteCookies()

c) Driver.manage().deleteAllCookies()

d) Driver.deleteCookies()


In webdriver, which methods navigate to a URL?

a) goToUrl(“url”)

b) navigate().to(“url”)

c) getUrl(“url”)

d) get(“url”)

If you want to validate that a button has appeared on a page, which two commands would be the best two to use?

(A) verifyTextPresent/assertTextPresent
(B) verifyElementPresent/assertElementPresent
(C) verifyAlertPresent/assertAlertPresent
(D) verifyAlert/assertAlert

How to select a value from a dropdown in Selenium WebDriver?

Select class in WebDriver is used for selecting and deselecting options in a dropdown. The objects of the Select type can be initialized by passing the dropdown web element as a parameter to its constructor.

WebElement testDrop = driver.findElement("testingDropdown"));

Select dropdown = new Select(testDrop);

WebDriver offers three ways to select from a dropdown:

selectByIndex: Selection based on index starting from 0


selectByValue: Selection based on value


selectByVisibleText: Selection of option that displays text matching the given argument

dropdown.selectByVisibleText(“The Alchemist”);

In Selenium webdriver, selectAllOptions() is a valid command.

a) True

b) False

Which of the following is used to toggle a checkbox in a web form?

a) Element.toggle()


c) Element.set()


Which of the following Selenium API enables running Selenium 1.0 tests in web driver?

a) Selenium RC

b) None of the listed options

c) Webdriver

d) WebDriverBackedSelenium

Which of the following will terminate the test when the check fails

a) Verify

b) Assert

What is the difference between the “/” and “//” in the X path?

Single Slash “/” – The Single slash is used to create Xpath with absolute path i.e. the XPath would be created to start selection from the document node/start node.

Double Slash “//” – The Double slash is used to create Xpath with a relative path i.e. the XPath would be created to start selection from anywhere within the document.

If you wanted to find the sibling input that is after input in the DOM, what would the XPath look like?

Ans: //input/following-sibling::input

What is meant by Selenese?

Selenium commands, also known as “Selenese” are the set of commands used in Selenium that run your tests. For example, command – open (URL); launches the desired URL in the specified browser and accepts both relative and absolute URLs. A sequence of Selenium commands (Selenese) together is known as a test script.

If an element got added after the page has loaded what command would you use to make sure the test passed in the future?

(A) waitForElementPresent
(B) pause
(C) assertElementPresent

What is the most common way to find an element on a page?

(A) Id
(B) Xpath
(C) CSS Selector
(D) Name

Pick two from the following if you wanted to do a partial match on an attribute on an element from the beginning of the value:

(A) contains()
(B) starts-with()
(C) ends-with()
(D) A & B

What is the best call for finding multiple elements using XPath?

(A) findElementByXpath
(B) findElementsByXPath
(C) findElementByCssSelector
(D) Both B & C

In Selenium webdriver, which of the following is a valid select statement that selects a value from a dropdown element?

a) All of the listed options

b) selectByIndex()

c) selectByValue()

d) selectByVisibleText()

Will a findElements type call throw a NoSuchElementException when it can’t find the element?

Ans: No, it will not throw an exception. It will return an empty list.

What versions of Internet Explorer does WebDriver support?

Ans: All versions of IE6, IE7, IE8, and IE9 for both 32-bit and 64-bit installations

Which of the following expression is used for “anything”?

(A) **
(B) .*
(C) *.
(D) *+

Which of the following is not a wait command in Selenium?

(A) waitForActive
(B) waitForAlert
(C) waitForTitle
(D) None of these

Which one is a class in Selenium?

(A) WebDriverWait
(B) WebElement
(C) WebDriver
(D) getPageSource

Selenium command for entering text into text boxes?

(A) sendKeys()
(B) sendKey()
(C) sendKey
(D) SendsKeys()

Which of the following language is not supported by Selenium

(B) C#
(D) Java

What is the best element locator in selenium webdriver?

(A) ID

Which of the following method is used to work with multiple browser windows?

(A) getMultipleWindows()
(B) getWindowHandles()
(C) getWindowhandle()
(D) Both B &C

Selenium method to get content that is inside any HTML tags?

(A) getText()
(B) getValue()
(C) get()
(D) getAttribute()

Select the odd one used in Selenium

(A) Pattern Matching
(B) XPath
(C) Id
(D) CSS selector

Key Points about Selenium Web driver!!

Load a web page in a current browser window using selenium

Loading a web page in the current browser window Here is a list of possible ways to load a web page


Web Page Back or forward methods in selenium Java

Navigation() below is the list of possible ways to navigate back or forward in selenium

Refresh page
refresh() is the only method to refresh the page in selenium


Selenium method to get the page title in java


Current URL Current url can be obtained using method getCurrentUrl()


Page Source Whole page source be collected using getPageSource() method


Locating web elements

– 0 match -> throws exception
– 1 match -> returns a WebElement instance
– 2+ matches -> returns only the first match from web page
– 0 match -> returns an empty list
– 1 match -> returns a list with one WebElement
– 2+ matches -> returns list with all matching WebElements

Inspecting elements in web browsers

– Firebug add-on (Right click -> Inspect element / F12)
– Firefinder add-on (Try out your CSS & Xpath expressions)
– Built-in (Right click -> Inspect element / F12)
– Built-in (Tools -> Developer Tools / F12)

Finding element by id

– Ideal solution, however…
– Ids don’t always exist
– Their uniqueness is not enforced
– Used by developers as well

Finding element by Class Name


Finding Element by Linktext

driver.findElement(By.linkText(”Sign in”));


Finding name by Name

<input id=”modCustLoginPassword” name=”password”>

Find element by tagName

Email address

Find elment by Support Classes

Return all that matches each of the locators in sequence

driver.findElements(new ByChained(by1, by2))

Return all that matches any of the locators in sequence

driver.findElements(new ByAll(by1, by2))

Find element by CSS Selector in selenium

Absolute path


Relative path


Attribute selection




Id selection


Class selection


Combined selection



First matching child of the specified tag


Nth matching child of the specified tag


First matching enabled tag


best way to finding element by XPath in selenium

Absolute path


Relative path


Attribute selection


Selenium Commands to handle dropdown select

select[ByIndex, ByVisibleText, ByValue]
deselect[ByIndex, ByVisibleText, ByValue]

Selenium methods to get page size in java

driver.manage().window().setSize(Dimension d);

Selenium methods to get Position in java

driver.manage().window().setPosition(Point p);

Selenium method to Handle windows in java

String windowHandle = driver.getWindowHandle();
Iterator windowIterator = browser.getWindowHandles();