How to Handle GWT suggestions using Selenium?

It is a very common pattern now a days that many web application are being developed using Google Web Toolkit and it can be very challenging to test such applications sometimes using selenium. For instance, last few days, I was struggling to go past a scenario where the suggest box of one field was masking another WebElement. For this reason the other WebElement was not getting located by Selenium and my test was failing. After many hit and trials, I found a way to solve this problem. The explanation of the solution goes as below.


Let’s assume that, there is text box called with id “city_id”. Below the field there is button with id “find”. While we type some city name in the city_id field, it suggest some cities with matching character. Then you select a city and click on the find button, you will displayed some result. Now the problem is, you type the whole city name and do and findElement for the find button. Since the suggestion box is open, selenium is unable to find the button and the test fails.


Here, after doing a sendKeys operation with the city name to the city_id field, we need to do another sendKey operation to press keyboard enter. Now the button becomes visible and selenium can happily find the same. Below is the sample code on how to do it.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s