1

I have a protractor test looking for a record in my infinite scroller component like this.

 searchPage.searchEntitlement('search criteria');
    var myHiddenElementInScroller = element(by.repeater('result in ctrl.results track by $index').row(12));
    browser.driver.executeScript(function () { arguments[0].scrollIntoView(); }, myHiddenElementInScroller .getWebElement());

myHiddenElementInScroller.click();

This is supposed to scroll to the element and click it. Instead its throwing me element not visible error.

Has anyone come across this situation? Any help greatly appreciated.

G1P
  • 98
  • 10

3 Answers3

1

You might need to explicitly wait for the scrolling into view actually happen:

browser.driver.executeScript("arguments[0].scrollIntoView()", myHiddenElementInScroller.getWebElement()).then(function () {
    myHiddenElementInScroller.click();
});

Or, with browser.actions():

browser.actions().mouseMove(myHiddenElementInScroller).click().perform();
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
1

In few scenarios the element which we are looking for will be covered with some other element from DOM.when protractor tries to click it,the click will be received by the element that covers the actual element. So in such situation you need to use native javascript click event. Look at the below code.

browser.executeScript("arguments[0].click()", myHiddenElementInScroller.getWebElement())

The above code will send a click event directly to the mentioned webElement even if it is visible or not.

NOTE: this is not the recommended way for clicking an element. but you can you this in scenarios where you have no other workaround to achieve the click event.

Sudharsan Selvaraj
  • 4,792
  • 3
  • 14
  • 22
  • @G1P please also see this thread for more information about pros and cons of this approach: http://stackoverflow.com/questions/34562061/webdriver-click-vs-javascript-click. – alecxe Jul 11 '16 at 12:09
  • @sudharshanalecxe, Have tried this also, but no success in clicking my 12th element in the infinite scroller. – G1P Jul 11 '16 at 13:08
0

Thanks for all the responses. I was able to resolve this issue by using element(by.CssContainingText(cssSelector, searchText)) locator.

G1P
  • 98
  • 10