我已经用Google搜索了几个小时,而且我非常难以让我的UI测试专注于弹出窗口。在这个阶段,我很乐意只需点击" PayBill",等待弹出窗口(立即加载),然后点击取消。
我的代码的最新版本为:
paybillButton.click();
browser.sleep(500);
browser.getAllWindowHandles().then(function (handles) {
newWindowHandle = handles[1];
browser.switchTo().window(newWindowHandle).then(function () {
cancelButton.click();
});
});
但它在browser.switchTo()
和.window(newWindowHandle).then ...
错误:
Failed: null value in entry: handle=null
WebDriverError: null value in entry: handle=null
at Object.checkLegacyResponse (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/error.js:505:15)
at parseHttpResponse (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/http.js:509:13)
at doSend.then.response (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/http.js:440:13)
at process._tickCallback (internal/process/next_tick.js:103:7)
From: Task: WebDriver.switchTo().window(undefined)
at thenableWebDriverProxy.schedule (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:816:17)
at TargetLocator.window (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:1755:25)
我还尝试了Failed: null value in entry: name=null error while switching Popup window ...
中的以下代码function windowCount(count) {
return function () {
return browser.getAllWindowHandles().then(function (handles) {
return handles.length >= count;
});
};
};
browser.wait(windowCount(2), 10000);
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[1]);
cancelButton.click();
});
但那会返回这个错误:
Failed: Wait timed out after 10002ms
TimeoutError: Wait timed out after 10002ms
at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2107:17
at ManagedPromise.invokeCallback_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1366:14)
at TaskQueue.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2970:14)
at TaskQueue.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2953:27)
at asyncRun (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2813:27)
at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:676:7
at process._tickCallback (internal/process/next_tick.js:103:7)
From: Task: <anonymous wait>
at scheduleWait (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2094:20)
at ControlFlow.wait (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2408:12)
答案 0 :(得分:0)
switchTo
方法是selenium-webdriver switchTo
方法的包装器。 switchTo
方法返回TargetLocator
对象,TargetLocator
对象没有window
方法。正确的方法是使用frame method。
browser.getAllWindowHandles().then((handles) => {
let newWindowHandle = handles[1];
browser.switchTo().frame(newWindowHandle).then(() => {
cancelButton.click();
});
});