SelectorsHub: The best xpath plugin for all the browsers

SelectorsHub helps to write and verify the XPath and cssSelector.

SelectorsHub is the complete new way to write and verify the XPath and cssSelectors.

SelectorsHub auto suggests all attributes, text and everything along with their occurrences to complete Selectors quickly. Now you need not to copy and paste attribute values from DOM anymore to build XPath and cssSelector. It also supports shadowDOM, iframe and SVG elements. It gives the proper error message like what is wrong in your xpath and cssSelector.

SelectorsHub is invented and created by Sanjay Kumar

How to install & use SelectorsHub?

Find the download link here. Try it now it’s absolutely FREE.

https://www.selectorshub.com/

  1. Click on the download link for whichever browser you want.

2) Click on Add to Chrome.

3) After adding the extension, it will show in the browser toolbar like this. You can pin to the toolbar by clicking on the pin icon.

4) After adding the extension, restart the browser.

5) Now open DevTools by right clicking on any element and clicking on inspect.

6) On the right side of the Elements tab, SelectorsHub will be the last tab as shown in below image. If not visible, expand the sidebar or click on the two arrow icons as shown in below gif.

7) Now here you start typing your xpath or cssSelector. You will get auto suggest for inspected element.

Why to use SelectorsHub while there are so many other good XPath tools & selectors tools?

Biggest reason is, SelectorsHub helps to improve XPath and cssSelector writing skills.

Not one reason, there are many reasons which makes SelectorsHub the unique and best xpath tool.

  1. SelectorsHub is the only tool which made it possible to write own selectors in less than 5sec with its auto suggest feature without compromising learning skills.
  2. SelectorsHub is the only tool which supports #shadowDOM, in fact even Chrome DevTools doesn’t support shadowDOM.
  3. SelectorsHub is the only tool which gives the proper error message for the missing elements in your selectors.
  4. It helps you to improve your xpath and cssSelectors writing skills.
  5. It has iframe support.
  6. It supports svg elements.
  7. It supports dark theme.

ShadowDOM Support

It was never possible to verify and write the cssSelectors for shadowDOM elements but this amazing innovation made it possible.

Proper error message for missing elements in selectors

Earlier there was nothing which can tell us what’s wrong in our selector. We were never able to understand what’s wrong in our selector until we are not expert in it. Devtools suggests 0 matching node for wrong selector pattern. But now we have the Selector’s guide which helps us with the correct error message and what is wrong or missing in our selector.

Iframe support


It supports iframes as well. It will let you know if the inspected element is inside an iframe or not. Now we can easily write and verify selectors for elements inside an iframe without wasting any time.

SVG element support

Many of us are not aware that svg elements don’t support the standard xpath format. SVG elements support different xpath patterns. SelectorsHub has made it easy and let you know the correct format and helps you to learn how to write selectors for svg elements.

Looking forward to see some more interesting features in SelectorsHub.

Core Java (For Automation Testers) – Interview Questions and Answers – Part 1

1. What is OOPS?

Object Oriented Programming System is the programming technique to write programs based on the real world objects. The states and behaviors of an object are represented as the member variables and methods. In OOPS programming programs are organized around objects and data rather than actions and logic.

2. What are the advantages of OOPS concepts?

Major advantages of OOPS programming are;
1. Simplicity: OOPS programming objects model real world objects, so the complexity is reduced and the program structure is clear.
2. Modularity: Each object forms a separate entity whose internal workings are decoupled from other parts of the system.
3. Modifiability: It is easy to make minor changes in the data representation or the procedures in an OO program. Changes inside a class do not affect any other part of a program, since the only public interface that the external world has to a class is through the use of methods.
4.  Extensibility: Adding new features or responding to changing operating environments can be solved by introducing a few new objects and modifying some existing ones.
5.  Maintainability: Objects can be maintained separately, making locating and fixing problems easier.
6.  Reusability: Objects can be reused in different programs1

3. What are the core concepts of OOPS?

OOPS core concepts are:
1. Abstraction
2. Encapsulation
3. Polymorphism
4. Inheritance
5. Composition
6. Association
7. Aggregation

4. Explain JDK,JRE and JVM in short.

JVM
JVM is an acronym for Java Virtual Machine, it is an abstract machine which provides the runtime environment in which java bytecode can be executed. It is a specification.
JVMs are available for many hardware and software platforms (so JVM is platform dependent).
JRE
JRE stands for Java Runtime Environment. It is the implementation of JVM.
JDK
JDK is an acronym for Java Development Kit. It physically exists. It contains JRE + development tools.

5. What is constructor?

Constructor is just like a method that is used to initialize the state of an object. It is invoked at the time of object creation.

6. What is the purpose of default constructor?

The default constructor provides the default values to the objects. The java compiler creates a default constructor only if there is no constructor in the class

7. Does constructor return any value?

Ans:yes, that is current instance (You cannot use return type yet it returns a value)

8. Is constructor inherited?

No, constructor is not inherited.

9. Can you make a constructor final?

No, constructor can’t be final.

10. What is static variable?
  •  static variable is used to refer the common property of all objects (that is not unique for each object) e.g. company name of employees,college name of students etc.
  •  static variable gets memory only once in class area at the time of class loading.
11. What is static block?
  • Is used to initialize the static data member.
  • It is executed before main method at the time of class loading.
12. Can we execute a program without main() method?

Yes, one of the way is static block.

13. What is final variable?

If you make any variable as final, you cannot change the value of final variable(It will be constant).

14. What is final method?

Final methods can’t be overriden.

15. What is final class?

Final class can’t be inherited.


Continue to: CORE JAVA (FOR AUTOMATION TESTERS) – INTERVIEW QUESTIONS AND ANSWERS – PART 2

Selenium Online Training with live project

About Selenium Online Training Course
With Selenium Training, We help you to learn Selenium. It is one of the top automation testing tool. As part of the training you will learn about Selenium components like Selenium IDE, RC, WebDriver and Grid through hands-on projects and case studies in this Selenium certification training.
What you will learn in this Selenium online Training Course?

Selenium Automated Testing advantages
Advanced study of SIKULI, TestNG Plugin in Eclipse
Learn about Object Repository and Maven
Introduction to Selenium WebDriver
WebDriver programs like Textbox, Checkbox and multiple Windows
Use Selenium Grid for software testing
Jenkins

Who should take this Selenium 3.0 Training Course?
Software Developers, Testers, QA Engineers
System Analysts, Administrators, BI and ETL professionals

What are the prerequisites for taking this Selenium Certification Training Course?
Having a basic knowledge of C or Java is beneficial but not mandatory for taking this Selenium certification training.

Topics to be covered:

Why Selenium script runs slow on IE browser as compared to other browsers like chrome and Firefox?

Why execution speed of Selenium in IE is slow?

If we are talking about execution speed then i would go with headless browser and htmlunit is a headless browser.

So as per my working experience have got that scripts in almost all browser get executed at the same rate except few of the exception in IE. But if we are going to include the browser up time then order is like this,

htmlunit –> Chrome –> Firefox –> at the last its IE

Now, why IE is slow?

Much of the functionality of WebDriver is implemented using so-called “automation atoms”. These are JavaScript functions that are used to ensure consistency and reduce maintenance across the different drivers. Some of these functions are fairly straightforward, and delegate down to the browsers’ native code fairly quickly. Finding an element by ID, for example, pretty clearly translates to document.getElementById().
Other operations, on the other hand, are much more computationally expensive. For example, getting the text of an element is one of the most expensive things you can do, Because of the way the WebDriver API defines getting an elements text.
Because so much of this functionality is built in JavaScript, a browser that has a slow JavaScript engine like IE Will show poor performance when executing WebDriver code. Remember that the JavaScript engine in IE before version 9 was about ten times slower than the JavaScript engines in Firefox and Chrome. IE9 introduced a new JavaScript engine that was a lot closer in performance to that of Firefox and Chrome, but Microsoft only implemented the new JavaScript engine in the 32-bit version of IE. So the first thing you can do is run your tests against the 32-bit version of IE9.
IE also doesn’t have a native XPath engine for finding elements. So to be able to find elements by XPath in IE, we have to use a JavaScript XPath query engine. That’s going to be slower than doing the same thing in other browsers. This is the biggest reason why I recommend using CSS selectors instead of XPath for finding elements.
I would also recommend calling expensive methods as seldom as possible. The two most expensive methods are getText() and isDisplayed(), because they have to walk a substantial portion of the DOM tree before they can return the correct value.

 

How to run testng.xml from POM.xml (maven)

In this article i will talk about how to run testng.xml from maven’s POM.xml file. This is very useful feature of maven when we need to run multiple testng.xml files.

run testng.xml from pom.xml maven

The very first thing is, install maven in your eclipse IDE. Refer below article to know about how to install maven in eclipse ide.

How to download and Install Maven in Eclipse IDE?

Now, create a maven project.  Refer below article to understand how to create new project in eclipse IDE.

How to create Maven Project for Selenium in Eclipse IDE?

Now, write one sample test case in one of the folder created by maven, preferably test folder.  I have created below sample code –

package kdf1;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class Sample {
  
  @Test
  public void test(){
    System.out.println("Test Print");
    System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    
    driver.navigate().to("http://demowebshop.tricentis.com/");
    driver.manage().window().maximize();
    
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
  }

}

Now, create testng.xml file for executing above test case. My testng.xml files looks like –

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default suite">
  <test verbose="2" name="Default test">
    <classes>
      <class name="kdf1.Sample"/>
    </classes>
  </test> <!-- Default test -->
</suite> <!-- Default suite -->

Now, create a POM.xml file, add required dependencies. My POM.xml looks like –

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com</groupId>
  <artifactId>kdf1</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <dependencies>
  <dependency>
  <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>2.53.0</version>
  </dependency>
  
  <!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.9.9</version>
    <scope>test</scope>
</dependency>
  
  </dependencies>
    
</project>

Now, My job is to execute above given testng.xml file from above created POM.xml file via maven commands.

To achieve this, we need to use Suite XML files. Add below lines of code in POM.xml under <build> tags.

Make sure that you give the full testng.xml path.

<plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.20.1</version>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
      </plugin>
</plugins>

After adding above piece of code in to my POM.xml (under <build> tags), my POM.xml looks like –

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com</groupId>
  <artifactId>kdf1</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <dependencies>
  <dependency>
  <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>2.53.0</version>
  </dependency>
  
  <!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.9.9</version>
    <scope>test</scope>
</dependency>
  
  </dependencies>
  <build>
  <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.20.1</version>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>C:\Users\Prakash\workspace\kdf1\testng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
      </plugin>
</plugins>
  </build>
  
</project>

Thats it, you are done.

You are good to execute your testng.xml file from maven’s POM.xml. The main advantage of using this is we can execute multiple testng.xml files.

You can execute the project now by right clicking on project, Run As –> Maven Test  (another way to execute test case is from command prompt).

This was all about how to run testng.xml from pom.xml.

To know more about how to execute maven commands from command prompt, refer below link –

Maven Build Life Cycle – How to execute maven project

 

Hope this helps !!!!! Do provide your valuable comments !!!

Introduction to maven – What is maven (Build tool)

Introduction to maven?

Maven is basically a project management tool, where we manage our projects, we can  build projects, deploy projects & many more features like reporting & documentation. It refers concept of Project Object Model (POM). In a short term, it is a build tool.

If you are using build tool like mavn, it simplifies your build process. everything becomes very simple because it follows some life-cycle what it has. we will talk about mavn life-cycle in couple of next para.

Why do we need maven project?

Earlier project who does not have mavn, they need to add jar files manually & if multiple persons are working on the same project, they have to use same jar files. If one has changed, it cause issues. Also earlier to mavn, we used to create project folder structure by our own. Where as after mavn, this is not manually required, because –

1. In case of maven project, you need not add any jar files in to the project. just add all your dependency in POM.xml file
2. Maven project creates a very good project folder structure for coding purpose.

So, in Short, Maven has two main purposes
  1. Project management (Includes creating folder structure, compiling, packaging etc.)
  2. Dependency management (update dependencies in POM.xml file to download jar automatically)

As i said earlier, maven is a build tool, now let us try and understand what us build tool.

Build tool has a set of processes, certain outcomes like compile source code, copying resources, compiling and running tests, packaging project(in jar or zip file based on selected option), deploying project & finally cleanup. So when you compile your source code using maven, it will create a jar or war file for further use.

All settings of maven project are POM.xml file

What is POM.xml?

POM is an xml file that contain an information about project and configuration details used by mavn to build project. Information is about name, version, artifact it, dependencies, plugin information & profiles. We will talk about POM.xml in more details in coming sessions.

What are important maven objectives?

  1. Making the build process easy.
  2. Provides the uniform build system.
  3. Provide quality project information.
  4. Providing guidelines for best practices development.
  5. Allowing transparent migration to new feature.]

Maven Build Lifecycle –

For the person building a project, this means that it is only necessary to learn a small set of commands to build any Maven project, and the POM will ensure they get the results they desired.

There are three built-in build lifecycles: default, clean and site. The default lifecycle handles your project deployment, the clean lifecycle handles project cleaning, while the site lifecycle handles the creation of your project’s site documentation.

Each of these build lifecycles is defined by a different list of build phases, wherein a build phase represents a stage in the lifecycle.

maven lifecycle

For example, the default lifecycle comprises of the following phases (for a complete list of the lifecycle phases, refer to the Lifecycle Reference):

  • validate – validate the project is correct and all necessary information is available
  • compile – compile the source code of the project
  • test – test the compiled source code using a suitable unit testing framework. These tests should not require the code be package or deploy.
  • package – take the compiled code and package it in its distributable format, such as a JAR.
  • verify – run any checks on results of integration tests to ensure quality criteria are met
  • install – install the package into the local repository, for use as a dependency in other projects locally
  • deploy – done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.

These lifecycle phases (plus the other lifecycle phases not shown here) are executed sequentially to complete the default lifecycle. Given the lifecycle phases above, this means that when the default lifecycle is used, Maven will first validate the project, then will try to compile the sources, run those against the tests, package the binaries (e.g. jar), run integration tests against that package, verify the integration tests, install the verified package to the local repository, then deploy the installed package to a remote repository.

I will talk about maven in more detail in next articles. Refer below links –

How to download and Install Maven in Eclipse IDE?

How to create Maven Project for Selenium in Eclipse IDE?

 

How to Install Maven in Eclipse IDE ? – Build Tool for java

In this article i will talk about how to install maven in eclipse IDE. Maven is basically a build tool for java based projects.

There are two ways to install maven in eclipse IDE. First one is to install directly in Eclipse IDE via Eclipse MarketPlace / Install new software from help menu of Eclipse IDE & second one is, Install it on your machine manually & then configure the installation details in Eclipse IDE.

Let us talk about both methods.

1.  Install maven directly in eclipse IDE via eclipse marketplace or install new software from help menu

Follow below steps one by one

Open Eclipse, Go to Help Menu on Top right hand side & click on install new software.

Install maven 1

Add depository for downloading M2e as shown in below image.

Install maven 1

Then select work with as the current URL that you have added. It will show you the list of Maven Integration tools for Eclipse IDE. Select the desired one & click on next. Shown in below image

Install maven 1

Click on the next, below screen will show you the current installation items that you have selected.

Install maven 1

Now accept the Terms and conditions of license agreement & click on finish button so as to start with installation of maven plugin inside eclipse IDE. Shown in below image.

Install maven 1

Finally, You can see that software installation has begin. Shown in below image

Install maven 1

Once installation is finished, do restart your machine.

This is how we can install maven inside Eclipse IDE.

 

2. Another way to install maven is Install it in your machine & then configure it in Eclipse IDE.

Follow below steps to get the installation done using above method.

Download Maven files from : https://maven.apache.org/download.cgi

or click here apache-maven-3.5.2-bin.zip

Then Extract it to some folder. Let us say i am extracting it in my C:/ drive. So path of maven files is : C:\apache-maven-3.5.2

Now, Setup Environment Variables.

Go to start program, type “env“, in search result you can find option to edit environment variables. Click on it. Refer below image –

install maven

Once you click on it, System properties will open. Click on Environment variables. As shown in below image.

install maven

Now add below variables by clicking on new button for system variables.

JAVA_HOME=C:\Program Files\Java\jdk1.8.0_111
M2_HOME=C:\apache-maven-3.5.2
M2=%M2_HOME%\bin

Once above variable setup is done, Edit the “Path” variable. Enter below path at the end of current path (Do not modify anything other than this unless you are sure about it)

Path=;%M2%;%JAVA_HOME%\bin

install maven

Once this is done, click on OK. Now you are done with environment variable setup. Now you can verify if maven is installed correctly on your machine or not.

To check this, open command prompt & type below command.

mvn -version

Result of above command should show the currently installed maven version (This means maven is installed correctly) Refer below image.

install maven

Next part is now, to configure this installed maven in to your eclipse IDE.

Before we update anything in Eclipse IDE, first we need to modify setting.xml file from maven installation directory. Here we need to add the path of current maven repository at correct position. refer below image.

Location of settings.xml file: C:\apache-maven-3.5.2\conf\settings.xml

install maven

In the above image, the highlighted line need to be inserted at correct position, as shown above. Save the file.

Now let us update Eclipse IDE. To do this, Click on Window & go to preferences of your Eclipse IDE.

Go to maven –> Installations. Window will looks like below.

install maven

Now click on Add, and add the path of your current maven directory here & Click on OK. refer below image.

install maven

Now go to user Settings in the same menu & add path of your settings.xml file (Located in conf folder of your maven installation directory)

install maven

Click on OK.

That’s it, now done.

Clean your project & start with new maven project. You should be good to start with creation of maven project.

Refer below video for the same –

Refer below article to know about how to create new maven project.

How to create maven project in Eclipse IDE

 

Put your comments if you have any issues !!!! Thanks !!

 

 

 

 

Selenium Interview Question and Answers – Part 1

On this page, you can find Basic Selenium Interview questions and answers which may benefit to freshers to experienced professional. This is part 1 of this interview questions series.

Very Basic Interview Questions –

1  What types of Testing are supported by selenium?

Functional Testing and regression testing

2. When should we go for selenium Grid?

Selenium Grid is used for test execution and not for test case design. It is used to execute test cases on same or different platforms on multiple machines parallel.

3. What is latest version of Selenium?

Selenium 3

4. What is difference between single slash (/) and double slash(//)?

/ – denotes that it is absolute Xpath ,that is starting from root node of the webpage
//- denotes it is relative Xpath, meaning, can starts from anywhere in the page.

5. What are different types of locators in selenium webdriver?

Id, class, Xpath, CSS, Name, Tagname, linkText, partial LinkText etc.

6. What is difference between assert and verify?

Assert – Test case terminated once assert fails.
verify – Test case is not terminated even if verify fails.

7. What are different types of drivers available in selenium WebDriver?

Firefox Driver, IEDriver, Chrome Driver, Safari Driver, HtmlUnitDriver etc.

 

 

Refer Part 2 onwards for advanced Interview Questions.

Selenium Interview Question and Answers – Part 3

In this Article, you can find Selenium Interview question and answers – Part 2. This is in continuation of Part2.

Selenium Interview Questions and Answers

11. How to handle alerts and confirmation boxes in Selenium WebDriver?.

Selenium provides an API to handle this. Alert alert().
Below are the methods present in Alert API, which are used to handle Alerts
void accept(): This is equivalent to the OK button action on the dialog. The corresponding OK button actions are invoked when the accept() action is taken on a dialog.
void dismiss():This is equivalent to clicking on the CANCEL action button.
java.lang.S tring getText(): This will return the text that appears on the dialog. This can be used if you want to evaluate the text on the modal dialog.
void sendKeys(java.lang.S tring keysToSend): This will allow the developer to type in some text into the alert if the alert has some provision for it.

12. How to handle colours in Selenium Webdriver ?

Get the value of a given CSS property. Color values should be returned as rgba strings, so, for example if the “background-color” property is set as “green” in the HTML source, the returned value will be “rgba(0, 255, 0, 1)”.

13. How to press shift +tab in Selenium?

public class SendKeys
{
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
WebElement searchBox = driver.findElement(By.name("q")); searchBox.sendKeys(Keys.chord(Keys.SHIFT, "packt publishing")); }
}

14. How to take a screenshot in selenium?

WebDriver driver = new FirefoxDriver(); driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere 

FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

15. Is there a way to click hidden link in Selenium WebDriver?

There is a easier way to work around the problem using JavascriptExecutor.
For example:

document.getElementsByClassName('post-tag')[0].click();

The above javascript would click on the “Selenium” tag on the top right of this page (next to your question), even if it were hidden.
All you need to do is issue this JS instruction via the JavascriptExecutor interface like so:

(JavascriptExecutor(webdriver)).executeScript("document.getElementsByClassName('post-tag')[0].click();");

16. What are the technical challenges that you faced with selenium?

Answer to this question differ person to person. Do tell all the challenges in real which you faced.

17. What is an Xpath in Selenium?

Xpath is used to locate a web element based on its XML path. XML stands for Extensible Markup Language and is used to store, organize and transport arbitrary data. It stores data in a key-value pair which is very much similar to HTML tags. Both being markup languages and since they fall under the same umbrella, Xpath can be used to locate HTML elements.

18. How to refresh a page without using context click?

1.Using sendKeys.Keys method

driver.get("https://accounts.google.com/SignUp");
driver.findElement(By.id("firstname-placeholder")).sendKeys(Keys.F5);

2.Using navigate.refresh() method

driver.get("url");
driver.navigate().refresh();

3.Using navigate.to() method

driver.get("url");
driver.navigate().to(driver.getCurrentUrl());

4.Using get() method

driver.get("url");
driver.get(driver.getCurrentUrl());

5.Using sendKeys() method

driver.get("https://accounts.google.com/SignUp");
driver.findElement(By.id("firstname-placeholder")).sendKeys("\uE035");

19. How to handle autocomplete box in web driver?

driver.findElement(By.id("your searchBox")).sendKeys("your partial keyword"); 
Thread.sleep(3000);
List <WebElement> listItems = driver.findElements(By.xpath("your list item locator")); listItems.get(0).click();
driver.findElement(By.id("your searchButton")).click();

20. Difference between the getWindowHandle and getWindowHandles.

getWindowHandles() –  Syntax: Set getWindowHandles()
Example: driver.getWindowHandles();
Purpose: Return a set of window handles which can be used to iterate over all the open windows of this Webdriver instance  by passing them to switchTo().WebDriver.Options.window() Returns: A set of window handles which can be used to iterate over all the open windows.

getWindowHandle() – Syntax: String getWindowHandle()
Example: driver.getWindowHandle();
Parameter: Return an opaque handle to this window that uniquely identifies it within this driver instance. This can be used to switch to this window at a later date.

 

Refer below posts for next interview questions –

Selenium Interview Questions and Answers – Part 1

Selenium Interview Question and Answers – Part 3

Selenium Interview Question and Answers – Part 4

Selenium Interview Question and Answers – Part 5