Handle Ajax in Selenium

Let’s see, How to handle Ajax in Selenium. First, let’s understand What is Ajax Auto Suggest ?

Ajax auto suggests or auto suggests drop list is system suggestion to the user. You can see Ajax Auto Suggestion in Google Search.

 

Open Google and type search keyword, google will display the suggestion related to that search keyword. This is what, We called Ajax auto suggest. In Many websites you can see, When you type text in Textbox and you will see text box will show you suggestion to auto fill the Text box.

 

Handle Ajax in Selenium

Here we will see, How we can handle Ajax Auto Suggest in selenium WebDriver.

Let’s take an example of Jquery website. Let’s open the URL -http://jqueryui.com/resources/demos/autocomplete/default.html

You will find the text box here. When you start to type something in this text box. It will show you some suggestion to auto fill. Suppose you type ‘Ja’ then it will show you two suggestion ‘Java’ and ‘JavaScript’.

 

Video Tutorial:

If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.

 

Let’s try to fill the second suggestion ‘JavaScript’ in a text box using selenium.(As we have seen in previous tutorials. We need explicit wait to handle the Ajax calls)

Auto Suggest using Selenium

In the above example, we can see, How we can select the option from auto select.

 

In the above example, we have stored the expected in textToSelect variable after that we have typed text in the text box and put the explicit wait for Ajax Auto Suggests.

After that, we have stored the all suggested options in the list and compared the expected with the list elements. And perform click if present.

 

So this is the way how we can deal with the Auto Suggest Ajax calls in Selenium. We can do the same work using some other ways as well, Script preparation always depends on your individual coding skills.

0 Comment

Leave a Reply