Top 10 Selenium Interview Questions with answers (2021).

Author: neptune | 05th-Jun-2021 | views: 21

What is the major difference between “assert” and “verify” cmd's in Selenium?

Both “assert” and “verify” commands check whether the given condition is true or false :

  • Assert: It stops the execution of the testing if the given condition is false else continue with the further tests.

 Example: assertEquals (expectedMessage, actualMessage);

  • Verify: It doesn’t stop the flow of execution irrespective of the condition being true or false. 

What is the difference between driver.close() and driver.quit() command in Selenium?

  • driver.close() It closes the currently active window on which the user is working.

  • driver.quit() It closes all the windows opened by the driver.

Note: Both the commands don’t take any parameter and don’t return any value either.

How can we create right-click and mouse hover actions in Selenium?

This code can replicate right-click action:

 actions action = newActions(driver);

 WebElement element = driver.findElement("elementId")); 


This code can replicate mouse hover action:

 actions action = newActions(driver);

 WebElement element = driver.findElement("elementId"));


Different types of Locating strategies in Selenium ?

Locating by ID:


Location by Name:


Location by Xpath:


Locating Hyperlinks by Link Text:

driver.FindElement(By.LinkText("edit this page")).Click();

Locating by ClassName


Locating by TagName


Locating by LinkText


Locating by PartialLinkText

driverlindElement(By.partialLinkText(" Neptune")).click();

What is the Syntax for defining explicit and Implicit wait for 10 seconds ?

Explicit Wait :

WebDriverWait wait = new WebDriverWait(driver, 10);

WebElement messageElement = wait.until(
Implicit wait :
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

What are the different types of navigation commands ?

driver.navigate().refresh(); - This method refreshes the current page.
driver.navigate().to(""); - Navigates to the provided URL.
driver.navigate().forward(); - This method does the same operation as clicking on the Forward Button of any browser. It neither accepts nor returns anything.
driver.navigate().back(); - This method does the same operation as clicking on the Back Button of any browser. It neither accepts nor returns anything.

How to scroll down a page using JavaScript?

First, create a JavaScript object.
   JavascriptExecutor js = (JavascriptExecutor) driver;
Scroll down to the desired location.
The window is scrolled vertically by 1000 pixels

Is there a way to type in a textbox without using sendKeys()?

Yes! Text can be entered into a textbox using JavaScriptExecutor
JavascriptExecutor js = (JavascriptExecutor) driver;
[email protected]”);

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

WebElement dp = driver.findElement("testingDropdown"));
Select dropdown = new Select(dp);
dropdown.selectByVisibleText(“Neptune World”);

How to upload a file in Selenium WebDriver? 

Browse button located

  WebElement browseBtn =driver.findElement("uploadfile"));

Pass the path of the file to be uploaded using sendKeys methods


Related Blogs
Related Blogs View More