在转到另一个网址

时间:2016-12-15 03:28:58

标签: intern leadfoot

在测试中,我点击了转到另一个页面的菜单按钮。之后,当我尝试在页面上找到任何元素时(页面存在,我可以看到它),错误'无法在关闭窗口中找到元素'不断出现。我试过直接获取网址,它工作正常。当测试单击一个按钮并转到另一个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

1 个答案:

答案 0 :(得分:0)

documentation确实说

  

findByXpath(path:string):承诺。

     

获取第一个   当前活动窗口/框架中与给定XPath匹配的元素   选择器。

因此,如果您想在上一个窗口中找到元素,则应使用switchToWindow使您想要查找元素的窗口处于活动状态