繁体   English   中英

滚动执行脚本的量角器不工作

[英]Protractor scrolling through executeScript not working

我正在测试我的Ionic应用程序。

在一个页面中,要单击的按钮超出了窗口的范围。 因此以下代码:

element.all(by.css('.item.item-complex')).get(9).click();

抛出错误:

ElementNotVisibleError:元素不可见

因此,我试图向下滚动页面以使按钮在页面中可见,然后尝试模拟其上的点击。 我使用以下代码:

browser.executeScript('window.scrollTo(0, 200);').then(function() {
    element.all(by.css('.item.item-complex')).get(9).click();
    expect(browser.getTitle()).toEqual('Vegeta The Prince');
});

但是上面的代码没有发生滚动。 请帮忙!

我正在使用Google Chrome。

当我遇到这样的问题时,我滚动到视图

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

elm.click();

我使用了解决了这个问题

window.scrollTo(x, y)

码:

var elm = element.all(by.css('.item.item-complex')).get(9);

elm.getLocation()
    .then(function (location) {
        return browser.executeScript('window.scrollTo(' + location.x + ', ' + location.y + ');')
    })
    .then(function () {
        return elm.click();
    })
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM