Selenium Interview Questions and Answers with Examples – 2 is our second post in this series.  Readers can get the first part

In this post, we are going to discuss about Selenium Interview Questions and Answers with Examples in detail. I am going to write this series which will be well suitable for Freshers as well as experienced candidates. Please post me whatever Selenium Interview Questions with or without Answers and with / without examples. Let us try to consolidate everything under one roof here.

Selenium Interview Questions and Answers with Examples – 2

Today, We shall go through – how to get the list of URLs displayed in Google Result Page.  This is one of the important interview question being asked in Selenium Interviews.  I shall share the Java Program for the same here with.  In this program, after printing all the links (identified with ahref) and we click on the third link available in the list of links.

package payilagam.webdriver.learning;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class GoogleSearchLearning {

public static void main(String[] args) {
// Setting up Chrome Driver
System.setProperty(“”, “E://Selenium//chromedriver_win32//chromedriver.exe”);

WebDriver webDriver = new ChromeDriver();


          // Identifying Search Inbox
WebElement searchBoxElement = webDriver.findElement(By.xpath(“//input[@name=’q’]”));
// Passing values to Search Box
searchBoxElement.sendKeys(“vikram”); // send also a “\n”
//  element.sendKeys(Keys.ENTER);
// Pressing Enter button

// wait until the google page shows the result – Explicit Wait
//WebElement myDynamicElement =
(new WebDriverWait(webDriver, 10))

List<WebElement> mySearchList = webDriver.findElements(By.xpath(“//*[@id=’rso’]//h3/a”));

// All the links will be printed here
for (WebElement webElement : mySearchList)
//   mySearchList.get(2).getAttribute(“href”);
//Get the url of third link and navigate to it
//  mySearchList.get(2).getAttribute(“href”);
String third_link = mySearchList.get(2).getAttribute(“href”);