在硒2 getWindowHandle中说:
安排命令检索当前窗口句柄。
但是当我尝试用从此处返回的句柄做某事时,它会抛出" NoSuchWindowError"。这怎么可能呢?如果是当前窗口,则不应该关闭它。如果关闭则当前窗口是另一个窗口。对?
是:
更新2:
好像是bug。关闭的窗口是facebook登录。
以下是如何重现:
提问:
我想获得窗口标题或类似名称,并不重要,我只需要句柄ID。
这是完整的错误堆栈,没有那么有用:
[8.572][SEVERE]: Unable to receive message from renderer
FF
(::) failed steps (::)
NoSuchWindowError: no such window: target window already closed
at Object.Future.wait (c:\app\node_modules\fibers\future.js:398:15)
at [object Object]._.extend.update (c:\app\tests\shared\Browser.js:183:62)
at [object Object].<anonymous> (c:\app\tests\shared\Browser.js:138:18)
at c:\app\node_modules\fibers\future.js:416:21
- - - - -
from unknown error: web view not found
(Session info: chrome=40.0.2214.111)
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86)
at new bot.Error (c:\app\node_modules\selenium-webdriver\lib\atoms\error.js:113:18)
at Object.bot.response.checkResponse (c:\app\node_modules\selenium-webdriver\lib\atoms\response.js:106:9)
at c:\app\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:362:20
at c:\app\node_modules\selenium-webdriver\lib\goog\base.js:1582:15
at [object Object].webdriver.promise.ControlFlow.runInNewFrame_ (c:\app\node_modules\selenium-webdriver\lib\webdriver\promise.js:1654:20)
at notify (c:\app\node_modules\selenium-webdriver\lib\webdriver\promise.js:465:12)
at notifyAll (c:\app\node_modules\selenium-webdriver\lib\webdriver\promise.js:442:7)
at resolve (c:\app\node_modules\selenium-webdriver\lib\webdriver\promise.js:420:7)
at [object Object].fulfill (c:\app\node_modules\selenium-webdriver\lib\webdriver\promise.js:535:5)
at c:\app\node_modules\selenium-webdriver\lib\webdriver\promise.js:1520:10
at c:\app\node_modules\selenium-webdriver\lib\goog\base.js:1582:15
at [object Object].webdriver.promise.ControlFlow.runInNewFrame_ (c:\app\node_modules\selenium-webdriver\lib\webdriver\promise.js:1654:20)
at notify (c:\app\node_modules\selenium-webdriver\lib\webdriver\promise.js:465:12)
at notifyAll (c:\app\node_modules\selenium-webdriver\lib\webdriver\promise.js:442:7)
at resolve (c:\app\node_modules\selenium-webdriver\lib\webdriver\promise.js:420:7)
at fulfill (c:\app\node_modules\selenium-webdriver\lib\webdriver\promise.js:535:5)
at c:\app\node_modules\selenium-webdriver\lib\goog\base.js:1582:15
at [object Object].webdriver.promise.ControlFlow.runInNewFrame_ (c:\app\node_modules\selenium-webdriver\lib\webdriver\promise.js:1654:20)
at notify (c:\app\node_modules\selenium-webdriver\lib\webdriver\promise.js:465:12)
at notifyAll (c:\app\node_modules\selenium-webdriver\lib\webdriver\promise.js:442:7)
at resolve (c:\app\node_modules\selenium-webdriver\lib\webdriver\promise.js:420:7)
at [object Object].fulfill (c:\app\node_modules\selenium-webdriver\lib\webdriver\promise.js:535:5)
at c:\app\node_modules\selenium-webdriver\lib\webdriver\promise.js:721:49
at c:\app\node_modules\selenium-webdriver\lib\webdriver\http\http.js:96:5
at IncomingMessage.<anonymous> (c:\app\node_modules\selenium-webdriver\http\index.js:131:7)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:943:16
at process._tickDomainCallback (node.js:463:13)
==== async task ====
WebDriver.getWindowHandle()
at [object Object].webdriver.WebDriver.schedule (c:\app\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:345:15)
at [object Object].webdriver.WebDriver.getWindowHandle (c:\app\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:672:15)
at [object Object].<anonymous> (c:\app\tests\shared\Browser.js:23:12)
at [object Object].fn [as f_getWindowHandle] (c:\app\node_modules\fibers\future.js:89:26)
at [object Object]._.extend.update (c:\app\tests\shared\Browser.js:183:42)
at [object Object].<anonymous> (c:\app\tests\shared\Browser.js:138:18)
at c:\app\node_modules\fibers\future.js:416:21
答案 0 :(得分:0)
尝试
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().forBrowser('chrome').build();
然后您会看到chrome已打开,请不要关闭它。然后尝试
driver.get('http://www.google.com')