0

在测试中,我单击一个菜单按钮转到另一个页面。之后,当我尝试在页面上查找任何元素时(该页面存在,我可以看到它),错误“无法在关闭的窗口上找到元素”不断出现。我试过直接获取网址,它工作正常。当测试单击一个按钮并转到另一个 url 时,我得到了这个错误。谁能帮我在实习生解决这个问题?

我正在使用 webdriver IEDriver 32bit,针对 IE11

代码 :

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();
        }
    });
});

控制台输出,错误:

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
4

1 回答 1

0

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

于 2016-12-19T13:21:39.283 回答