Protractor - Scroll down and click

孤街醉人 提交于 2019-12-23 03:08:36

问题


I'm trying to simply scroll down in table and click on the element.

This is function which I have:

    var scrollIntoView = function () {
        arguments[0].scrollIntoView();
    }

    element.all(by.css('div.ui-grid-selection-row-header-buttons')).then(function(arr) { 
    var row = arr[8]; 
    browser.executeScript(scrollIntoView, row.getWebElement()).then(function () { 
    row.click(); 
    }); 
    });

This script actually work and even scroll down, bproblem start when i use higher number (index) in arr[];

For example 8 work, but if i use 20 it don't and I'm pretty sure there are like 50 values there so problem in that.

Any hint will help guys


回答1:


If you want to scroll to an element you can use

    browser.actions().mouseMove(element).perform();

After that the browser will be focusing the element.




回答2:


This tested example demonstrate how to scroll to an element using javascript and click the same element .

it('scroll to element', function() {
       browser.driver.get('https://www.seleniumeasy.com/');
        var btnSubscribe= element(by.id('mc-embedded-subscribe'));
         browser.executeScript("arguments[0].scrollIntoView();", btnSubscribe);
         browser.sleep(2500);
         btnSubscribe.click();
      });



回答3:


You can actually do something like this:

$$('div.ui-grid-selection-row-header-buttons').each(function (ele) {
    browser.actions().mouseMove(ele).click().perform();
});

$$ actually represents element.all(by.css('.abc'))

Also you can use filter() if you don't want to click on all the elements but pick elements based on filter criteria like this: https://www.protractortest.org/#/api?view=ElementArrayFinder.prototype.filter



来源:https://stackoverflow.com/questions/28828306/protractor-scroll-down-and-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!