Selenium Interview Questions Part 5

In this selenium interview questions series, we will cover questions from basics to advance level which are mostly asked in companies interviews.You are also welcome to add questions faced by you in interviews. It may help some one. If you find any discrepancies in answers or have any suggestion , do let us know.

Note : You can add questions and answer in comments section after the post. We will add them to the series if not duplicated.


41) How to count no. of links available on a webpage?

As we know there is going to be a collection of elements. So, we can find out list of webelements by using method ‘findelements()’ and check its size.

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
List<WebElement> allitems = driver.findElements(By.tagName("a"));
System.out.println("Total no. of links : "+allitems.size());

42) How would open the application suppose gmail in different browsers like chrome, Firefox, Internet explorer, safari etc?

You can check this post to learn it in details.

43) Can Selenium handle windows based pop ups?

No, Selenium is used for automating web based application. But with the help of third party tools like AutoIT, this scenarios can be handled.

44) How can we handle web based pop-ups or sat alert boxes?

Selenium provides an interface called Alert which is used to handle pop-ups like Confirm box, alert box , prompt box etc. We have the following method to perform desired operations on pop-ups.

  • void dismiss() – The dismiss() method performs clicking on the “Cancel” button as soon as the pop up window appears.
  • void accept() – The accept() method performs clicking on the “Ok” button as soon as the pop up window appears.
  • String getText() – The getText() method returns the text displayed on the alert box.
  • void sendKeys(String stringToSend) – The sendKeys() method enters the specified string into the alert box.

You can use it in the way shown below.

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

For more details , check this post having examples and code.

45) What is the difference between setSpeed() and Thread.sleep() methods?

Thread.sleep(): It accepts the integer value and pause the execution for the specified amount of time in ms. It will pause only once for the particular statement in the test script.

e.g. Thread.sleep(2000)   // wait for 2 seconds

setSpeed(): It also accepts the integer value and pause the execution for the specified amount of time in ms. BUt the difference is that it will wait for each and every steps for the time mentioned.

e,g, setSpeed(2000)

It is good for demo purpose if you have the slow application.

46) How do I clear content of a text box in selenium webDriver?

You can use the method clear().


47) Can we run test cases without having the browser window?

Yes, answer would be HTMLUnitDriver.This is currently the fastest and most lightweight implementation of WebDriver. It will run all the functionality behind the scene without opening the browser window. It is based on pure java solution and platform independent.

48) How can you execute the javascript functions?

JavascriptExecutor js = (JavascriptExecutor) driver;

String title = (String) js.executeScript("pass your java scripts");

49) How can we select radio buttons?

You need to simply use the click() method.

WebElement el_radio = driver.findElement("element id"));;   //select the radio button

//verify if radio button is selected or not

50) How to get the source page of any web page?

String strPsource = driver.getPageSource();


Avatar photo

Shekhar Sharma

Shekhar Sharma is founder of This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...