简体   繁体   中英

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": i.stack.imgur.com/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. i.stack.imgur.com/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: i.stack.imgur.com/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.

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, "\(");
  2. blur on the input field (optional I think): selenium.fireEvent(LOCATOR, "blur");

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

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM