向下滚动到带有量角器的元素

and*_*epm 11 javascript scroll jasmine protractor

我在页面上有一个元素,我正在测试,我必须向下滚动才能看到.当我执行我的测试时,我得到的 元素在点(94,188)处不可点击.

我尝试了以下方法:

dvr.executeScript('window.scrollTo(0,250);');
Run Code Online (Sandbox Code Playgroud)

但它没有用.有谁知道这是如何工作的?

Rah*_*ddy 40

这回答你似乎很晚..但无论如何,

以下代码帮助我删除Element不可点击的错误.

var elm = element.all(by.css('.your-css-class')).get(9);
browser.executeScript("arguments[0].scrollIntoView();", elm.getWebElement());

elm.click();
Run Code Online (Sandbox Code Playgroud)

基本上这可以让你滚动到你的视图..


小智 9

window.scrollTo(x,x)解决方案并没有为我工作.特别是在测试纹波仿真器时.我设法使用scrollIntoView方法使其工作.

var scrollToScript = 'document.getElementById("ELEMENT ID").scrollIntoView();';

browser.driver.executeScript(scrollToScript).then(function() {
  element(by.id('ELEMENT ID')).click();
  expect(...);
});
Run Code Online (Sandbox Code Playgroud)


Jam*_*son 5

'use strict';

/**
 * Vertically scroll top-left corner of the given element (y-direction) into viewport.
 * @param scrollToElement element to be scrolled into visible area
 */
function scrollTo(scrollToElement) {
    var wd = browser.driver;
    return scrollToElement.getLocation().then(function (loc) {
        return wd.executeScript('window.scrollTo(0,arguments[0]);', loc.y);
    });
};
Run Code Online (Sandbox Code Playgroud)

用法:

scrollTo(element(by.css("div.someclass")));
Run Code Online (Sandbox Code Playgroud)

免责声明:此代码来自sg-protractor-toolsscroll.js
代码已获得MIT许可。


raj*_*har 2

我认为这对你有帮助:

dvr.executeScript('window.scrollTo(94,188);').then(function() {
    element(by.<<here your button locator>>).click();
})
Run Code Online (Sandbox Code Playgroud)

您的网络驱动程序无法读取该点(1254,21),原因是您的量角器浏览器无法覆盖您要测试的整个页面,然后我们给出一个命令,使浏览器滚动到该点(1254,21) ),然后执行点击操作