gpt4 book ai didi

node.js - 当它应该返回当前窗口句柄时,为什么我会收到 "NoSuchWindowError"错误和 "getWindowHandle"?

转载 作者:太空宇宙 更新时间:2023-11-04 02:28:42 25 4
gpt4 key购买 nike

Selenium 2 getWindowHandle说:

Schedules a command to retrieve they current window handle.

但是当我尝试使用由此返回的句柄执行某些操作时,它会向我抛出“NoSuchWindowError”。这怎么可能?如果是当前窗口,则不应关闭它。如果关闭则当前窗口是另一个窗口。正确的?

使用:

  • 用于 javascript/node.js 的 Webdriver;
  • ChromeDriver;

更新2:

看起来像 bug 。关闭的窗口是 Facebook 登录窗口。

以下是重现方法:

  • 转到某个请求 Facebook 登录的页面;
  • 出现 Facebook 登录弹出窗口;
  • 您登录;
  • 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

最佳答案

尝试

var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().forBrowser('chrome').build();

然后你会看到 chrome 已打开,不要关闭它。然后尝试

driver.get('http://www.google.com')

关于node.js - 当它应该返回当前窗口句柄时,为什么我会收到 "NoSuchWindowError"错误和 "getWindowHandle"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28633040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com