Dob
Dob

Reputation: 21

Google places autocomplete with Selenium IDE test

I'm trying to make test in Selenium IDE (from Firefox addon) for autocomplete place (given from google places). I need type in input place name and get the first location.

Sequence for place "Rzeszów, Polska": https://i.sstatic.net/gqRMd.png

Firstly I've tried mouseOver and Click action - elements exists but didn't make a click on autocomplete. Next I've tried two another sequences (with clickAt and KeyDown), but also didn't make a click, despite the fact that Selenium can find correct locator. https://i.sstatic.net/F13q7.png

I was trying my solution for jQuery autocomplete -> jqueryui.com/autocomplete/ and it worked fine there.

I think, problem is connected with html structure, with bold in place name: https://i.sstatic.net/BfLyE.png

You can test it on: jsfiddle.net/dodger/pbbhH/

My sequence in Selenium IDE (shown above) doesn't work for google places, could anyone solved this problem with autocomplete?

//Moderator: Please add photos and create links to my post and delete this line. Thanks.

Upvotes: 1

Views: 1883

Answers (1)

obecker
obecker

Reputation: 2377

To force the places autocompletion list to appear I had to send single keydown and keyup events to the input field. Like this:

    selenium.focus(LOCATOR);
    selenium.type(LOCATOR, ""); // clear the field
    for (int i=0; i<value.length(); i++) {
        String c = String.valueOf(value.charAt(i));
        selenium.keyDown(LOCATOR, c.toUpperCase());
        selenium.keyPress(LOCATOR, c);
        selenium.keyUp(LOCATOR, c.toUpperCase());
    }

Finally, to select an entry of the list, I've got it working by simulating keyboard events (since I also had no luck with mouse events).

  1. keyDown with the arrow down key: selenium.keyDown(LOCATOR, "\u0028");
  2. blur on the input field (optional I think): selenium.fireEvent(LOCATOR, "blur");

LOCATOR is the locator for your input field. \u0028 is the key code for arrow down (hex 28 or dec 40)

Hope this helps.

Upvotes: 3

Related Questions