Skip to main content


Selenium with Java Interview Questions and Answers

What exception will be thrown when we use "findElement" method?

will be thrown when the locator is not found in the DOM and no longer available.

How will you handle popups windows in Selenium?

We can handle popups in Selenium is simple. It provides various methods from WebDriver interface. They are,

1. getWindowHandle()
2. getWindowHandles()

getWindowHandle() - deals with current window
getWindowHandles() - it manages with multiple windows and returns set of instances

Let me show an example to understand this better,

import java.util.Iterator; import java.util.Set; import org.openqa.selenium.firefox.*; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import org.testng.annotations.AfterTest;
public class PopupDemo { 
private WebDriver driver; 
@BeforeTest  public void setUp()  { System.setProperty("webdriver.firefox.bin", "C:\\Users\\smshri\\AppData\\Local\\Mozi…
Recent posts

Query to find Nth Maximum and Minimum value from the Table

This query will fetch the rows which is the most large value / maximum value.
--Maximum value
SELECT MAX( spend )
  FROM edw_aggregate.vw_agg_order_automation
 WHERE spend < ( SELECT MAX( spend )
                 FROM edw_aggregate.vw_agg_order_automation );

The above query will only fetch top most value from the table. If we want to fetch Nth  maximum / minimum value, look into this query.

--Nth Minimum/Max
SELECT MIN( spend )
  FROM edw_aggregate.vw_agg_order_automation
  where spend in (SELECT top 5 spend FROM edw_aggregate.vw_agg_order_automation order by spend desc)


How to Handle Plain Javascript alert dialog buttons using Selenium with Java?

I have HTML page like this,
<input type="button" id="btnlogin" value="Login" onclick="goToRegister()">
And the javascript is,
<script language="javscript" type="text/javascript"> function goToRegister(){ alert("Login Successful!"); window.location.href="Register.html";}</script>In the selenium script,

@Testpublicvoid goToRegisterPage(){System.out.println("goToRegisterPage");WebDriverWait wait =newWebDriverWait(driver,10);Alert alert = wait.until(ExpectedConditions.alertIsPresent()); alert.accept(); driver.get("file:///X://selenium//Register.html");}@BeforeMethodpublicvoid beforeMethod(){System.out.println("beforeMethod called "+ visitcount++);System.setProperty("webdriver.gecko.driver","X:\\Selenium\\geckodriver-v0.17.0-win32\\geckodriver.exe"); driver =newFirefoxDriver(); driver.manage().timeouts()…