量角器滚动 executeScript 不工作
Protractor scrolling through executeScript not working
我正在测试我的 Ionic 应用程序。
在一个页面中,要点击的按钮超出了window的范围。
因此以下代码:
element.all(by.css('.item.item-complex')).get(9).click();
抛出错误:
ElementNotVisibleError: element not visible
因此,我试图向下滚动页面以使按钮在页面中可见,然后尝试模拟点击它。我正在使用以下代码:
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();
})
})
我正在测试我的 Ionic 应用程序。
在一个页面中,要点击的按钮超出了window的范围。 因此以下代码:
element.all(by.css('.item.item-complex')).get(9).click();
抛出错误:
ElementNotVisibleError: element not visible
因此,我试图向下滚动页面以使按钮在页面中可见,然后尝试模拟点击它。我正在使用以下代码:
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();
})
})