Handle search suggestions using selenium

SuggestionsTxtThere are certain types of textbox designed for browser apps which provides suggestions based on the string typed,

The suggestions may be based on predefined options (e-commerce category or flight booking sites) or based on previous searches done (like on google searchbox).

Let’s see how to capture google suggestion options through code:

To explain this, have a look at the screenshot, which shows the html part of suggestion options, it’s not dropdown options rather list items

Suggestionhtml

class = sbsb_b contains all the list options, so 1st get the webelement suggestion

now let’s grab all the list options in a List, variable options

each list item have one webElement common, that is class=sbqs_c which actually contains the text we are looking for, that’s it

Let’s grab the text and do whatever you want!

If we want to select the required list option, then just click the respective option webelement inside the for loop.

Same way, you can try with “FROM” field of http://www.jetairways.com/EN/IN/Home.aspx





 

Content posted is based on learning or working experience, Share the post with others if find useful, Any queries?, leave comments or discuss on our facebook:qavalidation.com, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: