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

133 Views Asked by At

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

There are 1 best solutions below

0
Jemi Artista On BEST ANSWER
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();