2016-12-01 100 views
2

不選擇的第一要素經過的部位來模擬自動完成應該選擇的第一要素。這裏是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"> 

這裏之後是量角器代碼:

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) 

回答

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); 

    }); 
}); 
+1

Thanks.it worked @BarretV – Shiva