clickprotractorautosuggestlistboxitems

How to click nth element from listbox of Google autocomplete suggestion using Protractor?


"get(n)" does not work to get the desired item from the suggestion.It shows error as "get is not defined". First(), Last() also does not work.Please suggest what should work?

My Protractor Code :

browser.driver.get('http://www.google.com');
search = browser.driver.findElement(by.css('.gsfi'));
search.sendKeys('Fifa');
searchInsideText = search.getAttribute('value');
searchInsideText.then(console.log);
browser.driver.sleep(2000);
suggestionItems = browser.driver.findElement(by.css('.sbsb_b ')).get(0).getText();
suggestionItems.then(console.log);

Solution

  • Found the solution:
    
    browser.driver.get('http://www.google.com');
    
    search = browser.driver.findElement(by.css('.gsfi'));
    search.sendKeys('fifa18');
    searchInsideText = search.getAttribute('value');
    searchInsideText.then(console.log);
    
    browser.ignoreSynchronization = true;
    browser.waitForAngular();
    browser.sleep(500);
    
    suggestionItems = element.all(by.css('ul.sbsb_b li')).get(2).getText();
    suggestionItems.then(console.log);
    suggestionItems.click();