"Unable to find element on closed window" error when finding an element after going to another url

161 views Asked by At

In the test I'm clicking a menu button that go to another page. Afterwards, when I try to find any element on page(The page exists, i can see it), the error 'unable to find element on closed window' keep appearing. I have tried directly getting the url and it works fine. It is when the test clicks a button and goes to another url that I get this error. Can anyone help me to resolve this in intern?

I'm using webdriver IEDriver 32bit, against IE11

Code :

define([
    "intern!object",
    "intern/chai!assert",
    "intern/dojo/node!leadfoot/Element",
    "intern/dojo/node!leadfoot/Server",
    "intern/dojo/node!leadfoot/helpers/pollUntil",
    "intern/dojo/node!leadfoot/keys",
    "require",
    "tests-config"
], function (registerSuite, assert, Element, Server, pollUntil, keys, require, config) {

    registerSuite({

        name: 'Test Suite Form Submissions',

        'Test Submit Form Step 1': function () {
            return this.remote
                .get(config.enter_doctor_url)
                .setFindTimeout(5000)

                .findByXpath("//span[text()='Create Case']")
                // goes to another url after clicking
                .click()
                .end()

               // error occurs here
               .findByXpath("//*[@id=\"js-wizard-eform\"]/fieldset[1]/table[2]/tbody/tr/td/div[1]/section[1]/label[2]/input")
               .pressKeys("John Doe")
               .end();
        }
    });
});

Console Output, Error:

C:\development\xeno1>intern run -w
FAIL: internet explorer 11 on any platform - Test Suite Form Submissions - Test Submit Form Step 1 (6589ms)
NoSuchWindow: [POST http://localhost:44444/wd/hub/session/5aef4686-29ed-40d5-a4e7-bd36982ef034/element / {"using":"xpath","value":"//*[@id=\"js-wiz
ard-eform\"]/fieldset[1]/table[2]/tbody/tr/td/div[1]/section[1]/label[2]/input"}] Unable to find element on closed window (WARNING: The server did not provide
any stacktrace information)
Command duration or timeout: 11 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'workstation', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, ie.enableFullPageScreenshot=true, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.forceShellWindowsApi=fa
lse, pageLoadStrategy=normal, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=
false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:255
50/, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss}]
Session ID: 3111becb-07c3-49cf-a151-e0c32a62a76c
*** Element info: {Using=xpath, value=//*[@id="js-wizard-eform"]/fieldset[1]/table[2]/tbody/tr/td/div[1]/section[1]/label[2]/input}
  at runRequest  <node_modules\leadfoot\Session.js:92:40>
  at <node_modules\leadfoot\Session.js:113:39>
  at new Promise  <node_modules\dojo\Promise.ts:411:3>
  at ProxiedSession._post  <node_modules\leadfoot\Session.js:67:10>
  at ProxiedSession.find  <node_modules\leadfoot\Session.js:1302:15>
  at Command.<anonymous>  <node_modules\leadfoot\Command.js:42:36>
  at <node_modules\dojo\Promise.ts:393:15>
  at run  <node_modules\dojo\Promise.ts:237:7>
  at <node_modules\dojo\nextTick.ts:44:3>
  at _combinedTickCallback  <internal\process\next_tick.js:67:7>
  at Command.find  <node_modules\leadfoot\Command.js:23:10>
  at Command.prototype.(anonymous function) [as findByXpath]  <node_modules\leadfoot\lib\strategies.js:29:16>
  at Test Doctor Submit Form Step 1 [as test]  <tests\functional\doctor-form-submission.js:44:18>
  at <node_modules\intern\lib\Test.js:191:24>
  at <node_modules\intern\browser_modules\dojo\Promise.ts:393:15>
  at runCallbacks  <node_modules\intern\browser_modules\dojo\Promise.ts:11:11>
  at <node_modules\intern\browser_modules\dojo\Promise.ts:317:4>
  at run  <node_modules\intern\browser_modules\dojo\Promise.ts:237:7>
  at <node_modules\intern\browser_modules\dojo\nextTick.ts:44:3>
  at _combinedTickCallback  <internal\process\next_tick.js:67:7>
1/1 tests failed
1/1 tests failed
1

There are 1 answers

0
Linh Nguyen On

The documentation does say

findByXpath(path: string): Promise.

Gets the first element in the currently active window/frame matching the given XPath selector.

So, if you want to find element in the previous window, you should use switchToWindow to make the window you want to find elements be active