While testing for a certain web application, I was faced with an issue of handling auto-complete scenarios. An example of this kind could be found here MagicBricks

I have few questions related to how we are supposed to handle such auto-complete scenarios.

  • Suppose I am entering a search word in the search box like Gurgaon. How does the auto-complete get populated? Is this due to some JS function written at back or does it pick values from a database?

  • I am no champion at JS, but I can see that the the with id localityKeywordDropDown has a visibility set to hidden. So the drop down options are not visible without entering any value. If I am writing test for it, how can I wait for these values to get populated? Right now I can think of using explicit waits, where I can wait for element to be present (correct me if I am wrong).

  • Suppose I am entering a text- Gurgaon Sector 51, which is at the bottom of the key words matching Gurgaon. How can I verify that the search string that I have searched is present within that list (using some kind of assert I would suppose)?

I assume that a few of the questions might cross the boundaries of SW Testing, so pardon me if this is the case. Any resources, links, relating to how we can handle these kind of scenarios will be appreciated. I found one here Handling auto complete using Selenium and Python

But I'm not quite sure if I understand how that is working.


  • Are you expected to test autocomplete (entering part of search term and waiting for autocomplete to fill the rest)? Or when you enter some value using send_keys(), autocomplete interferes with the value you entered? Jun 23, 2015 at 16:04
  • The later one sounds the one I'm looking for Jun 23, 2015 at 16:23

1 Answer 1


From a quick look at the site, it appears that you only see the elements in the source after you mouseover so first thing to do is enter "guragon"

//Wait for the results
        WebElement autofill= wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("keyword_suggest")));

you will then need to iterate through the divs/spans below it to create a list of results and check if it is returned

    List<WebElement> allElements = driver.findElements(By.xpath("//div[@id='keyword_suggest']/div/span")); 

    for (WebElement element: allElements) {
          if (element.contains("THE NAME YOU WANT")){

Hope that helps! (please note that although i tried to make the code applicable some is psudo code)

  • if the dropdown doesnt stay open long enough to be picked up, adding in a "key down" appears to keep it open a bit longer
    – ECiurleo
    Jun 26, 2015 at 15:31
  • Where did you get //div[@id='keyword_suggest']/div/span from ?
    – Siddharth
    Nov 26, 2016 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.