谷歌自动完成没有选择量角器中的第一个元素

时间:2016-12-01 13:27:44

标签: google-maps google-maps-api-3 autocomplete protractor

将位置传递给模型自动完成后应选择第一个元素。这是HTML代码

<input type="text" class="textareanoborder col-xs-12 col-md-12 m-t ng-pristine ng-valid ng-isolate-scope ng-touched" placeholder="Enter Location" ng-autocomplete="result1" details="details1" options="options1" rows="1" ng-model="location" autocomplete="off" aria-invalid="false">

这是Protractor代码:

browser.actions().mouseMove(element(by.model("location")).sendKeys("hyderabad,Telangana,India",protractor.Key.ARROW_DOWN)).click();

抛出错误:

Failed: unknown error: Element is not clickable at point (736, 231). Other element would receive the click: <div class="pac-item">...</div>
      (Session info: chrome=54.0.2840.99)
      (Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 10.0.14393 x86_64)

1 个答案:

答案 0 :(得分:2)

我猜这是一个嵌入式谷歌搜索?我不知道这是否会有所帮助,但我发现了一项搜索谷歌搜索中弹出的自动完成选项的功能。您可以选择要搜索的自动填充项目的编号。

function autoCompleteSearch(text, index) {
      browser.actions()
      .mouseMove(element(by.name('q'))
      .sendKeys(text))
      .perform().then(function(){
        browser.sleep(500);
        // press the down arrow for the autocomplete item we want to choose
        for(i = 0; i < index ; i++){

            browser.actions().sendKeys(protractor.Key.ARROW_DOWN).perform();
        }
        browser.sleep(500);
        browser.actions().sendKeys(protractor.Key.ENTER).perform();
      });
}

describe('google homepage', function() {
browser.ignoreSynchronization = true;
  beforeEach(function() {
    browser.get('http://www.google.com');
  });

  it('should search google via autocomplete', function() {

      autoCompleteSearch("awesome", 3);

      // added this sleep so I can see the results afterwards
      browser.sleep(2000);

  });
});