我的应用程序中有一个功能,当提交报告时,“报告”选项卡将自动关闭,但是在自动化中,我遇到以下错误,如何解决此问题?
错误是
D:\e2eWorkspace\fem_e2e\node_modules\selenium-webdriver\error.js:580
throw new ctor(value['message'] + '');
^
NoSuchWindowError: no such window: target window already closed
from unknown error: web view not found
(Session info: chrome=67.0.3396.87)
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.16299 x86_64)
at Object.checkLegacyResponse (D:\e2eWorkspace\fem_e2e\node_modules\selenium-webdriver\error.js:580:13)
at D:\e2eWorkspace\fem_e2e\node_modules\selenium-webdriver\lib\webdriver.js:360:15
at Promise.invokeCallback_ (D:\e2eWorkspace\fem_e2e\node_modules\selenium-webdriver\lib\promise.js:1329:14)
at TaskQueue.execute_ (D:\e2eWorkspace\fem_e2e\node_modules\selenium-webdriver\lib\promise.js:2790:14)
at TaskQueue.executeNext_ (D:\e2eWorkspace\fem_e2e\node_modules\selenium-webdriver\lib\promise.js:2773:21)
at asyncRun (D:\e2eWorkspace\fem_e2e\node_modules\selenium-webdriver\lib\promise.js:2652:27)
at D:\e2eWorkspace\fem_e2e\node_modules\selenium-webdriver\lib\promise.js:639:7
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
我的代码是
// below steps opens the report in new tab
reportPO.notSubmittedButton.first().click();
browser.sleep(6000);
browser.driver.getAllWindowHandles().then(function (handles) {
var secondWindowHandle = handles[1];
// switching to report tab
browser.switchTo().window(secondWindowHandle).then(function () {
browser.sleep(6000);
/**
* here, steps to add values in the form fields
*/
browser.driver.executeScript('window.scrollTo(0,10000);').then(function () {
// below step - click on save button on report
reportPO.saveButtonOnReport.click();
// here I am validating the message
commonPO.notifyMsg.getText().then(function (actualResult) {
expect(actualResult).toEqual(MessagesPD.pilotReportNotSubmitted.message);
});
// before report tab closing, I am switching driver back to parent tab
browser.switchTo().window(originalHandle).then(function () {
console.log('moved');
});
});
});
});
答案 0 :(得分:0)
使用以下代码返回上一个标签:
browser.getAllWindowHandles().then(function(handles) {
newWindowHandle = handles[1]; // this is your new window
browser.switchTo().window(newWindowHandle);
});