Friday, December 29, 2017

How to handle Google dynamic search (auto suggestions) in Selenium?

This is one of the most asked Selenium interview question and this question is to test our ability to handle dynamic objects.

The scenario is when we are searching some text say "seleniumhq" in Google, we will get some auto suggestions listed while we are entering the text and we need to click on the suggestion that matches with our requirement (here our requirement is "seleniumhq").

The auto suggestions will be listed in a web list as shown in the below image.


We will follow below steps to achieve this challenge
  • First we need to locate the list ('ul') 
  • Then gather all the suggestion elements ('li'). 
  • Now loop through the suggestion elements and compare the text in it with the expected text.
  • If texts matched click on the suggestion, and break the process.
Check out the code below for better understanding.

The screenshot looks like below after clicking on the required suggestion.


Now we are able handle dynamic Google search, Great!!. Please comment your queries and suggestions on this topic. Thanks for reading!!
#seleniumbabu #HappyLearning

3 comments:

Katalon 08: Integration of HP ALM with Katalon Studio

In this post, this post we discuss about integration of  HP ALM with Katalon Studio. If we can integrate HP ALM with Katalon we can update ...