我通常使用以下命令:
browser.driver.executeScript('window.scrollTo(0,1600);');
但它不再起作用了。
控制台没有错误,因此调试非常困难。
实际上,它适用于另一个测试用例,但我找不到脚本之间的差异。
所以我尝试使用 scrollIntoView 但是我有一个无限的og无限循环。
完整的测试用例 -
describe('My business page ', function() {
var EC = protractor.ExpectedConditions;
var loginBox = element(by.css("div.info-box.client-login.ng-scope"));
var centerElm = $$(("div.action-extra-content.wysiwyg-content.ng-binding.layout-column")).first();
var scrollIntoView = function (element) {
arguments[0].scrollIntoView();
};
beforeEach(function() {
browser.ignoreSynchronization = true;
});
afterEach(function() {
browser.ignoreSynchronization = false;
});
it('Main page - Top', function() {
browser.get('https://live.vcita.com/site/bungee');
browser.wait(EC.visibilityOf(loginBox), 30000);
browser.driver.sleep(5000);
});
it('Main page - Center', function() {
browser.executeScript(scrollIntoView, centerElm);
console.log("Scroll me!!!")
browser.driver.wait(EC.elementToBeClickable(centerElm),30000);
browser.driver.sleep(2000);
});
});
错误:
RangeError: Maximum call stack size exceeded
Stacktrace:
RangeError: Maximum call stack size exceeded
at Function.childCtor.base (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\base.js:2163:38)
at promise.Callback_.goog.defineClass.constructor (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2431:23)
at new wrappedCtr (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\base.js:2366:26)
at promise.Promise.addCallback_ (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:641:12)
at promise.Promise.then (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:591:15)
at Object.promise.asap (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:911:11)
at C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:250:27
at goog.object.forEach (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\object\object.js:35:7)
at convertKeys (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:245:5)
at convertValue (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:216:16)
From: Task: Asynchronous test function: it()
at [object Object].<anonymous> (C:\automation\npm\node_modules\protractor\node_modules\jasminewd\index.js:93:33)
at [object Object].<anonymous> (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\async-callback.js:45:37)
at [object Object].jasmine.Block.execute (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:1174:17)
at [object Object].jasmine.Queue.next_ (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2209:31)
at [object Object]._onTimeout (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2199:18)
Error
at [object Object].<anonymous> (c:\automation\tests\testCases\newApp\livesiteClient.js:26:3)
at [object Object].jasmine.Env.describe_ (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:913:21)
at [object Object].jasmine.Env.describe (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:898:15)
at describe (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:658:27)
at Object.<anonymous> (c:\automation\tests\testCases\newApp\livesiteClient.js:1:63)
答案 0 :(得分:1)
可滚动容器可能不是窗口/文档。要使用给定元素执行脚本,您需要提供.getWebElement()
返回的本机元素:
var elm = $('...');
browser.executeScript(function(e){
e.scrollIntoView();
}, elm.getWebElement());