简体   繁体   English

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

[英]Protractor scrolling through executeScript not working

I am testing my Ionic app. 我正在测试我的Ionic应用程序。

In one page, the button to be clicked is out of the bounds of the window. 在一个页面中,要单击的按钮超出了窗口的范围。 Hence the following code: 因此以下代码:

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

throws the error: 抛出错误:

ElementNotVisibleError: element not visible ElementNotVisibleError:元素不可见

Hence, I am trying to scroll down the page to make the button visible in page and then try emulating the click on it. 因此,我试图向下滚动页面以使按钮在页面中可见,然后尝试模拟其上的点击。 I am using the following code: 我使用以下代码:

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');
});

But the scrolling is not happening with the above code. 但是上面的代码没有发生滚动。 Please help! 请帮忙!

I am using Google Chrome. 我正在使用Google Chrome。

When I encounter issues like this, I scroll into view : 当我遇到这样的问题时,我滚动到视图

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

elm.click();

I solved this issue using 我使用了解决了这个问题

window.scrollTo(x, y)

code: 码:

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