如何重新连接到 webdriver 使用 selenium 打开的浏览器? [英] How can I reconnect to the browser opened by webdriver with selenium?

查看:29
本文介绍了如何重新连接到 webdriver 使用 selenium 打开的浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些未知原因,我的浏览器打开远程服务器的测试页面非常缓慢.所以我在想如果我可以在退出脚本但不执行 webdriver.quit() 后重新连接到浏览器,这将使浏览器保持打开状态.它可能是一种 HOOK 或 webdriver 句柄.我查找了 selenium API 文档,但没有找到任何功能.我正在使用 Chrome 62、x64、windows 7、selenium 3.8.0.问题能否解决,我将不胜感激.

For some unknown reasons ,my browser open test pages of my remote server very slowly. So I am thinking if I can reconnect to the browser after quitting the script but don't execute webdriver.quit() this will leave the browser opened. It is probably kind of HOOK or webdriver handle. I have looked up the selenium API doc but didn't find any function. I'm using Chrome 62,x64,windows 7,selenium 3.8.0. I'll be very appreciated whether the question can be solved or not.

推荐答案

,退出脚本后无法重新连接到之前的Web Browsing Session.即使您能够从之前的 Browsing Context 中提取 Session IDCookies 和其他会话属性,您仍然无法提取将这些属性作为 HOOK 传递给 WebDriver.

No, you can't reconnect to the previous Web Browsing Session after you quit the script. Even if you are able to extract the Session ID, Cookies and other session attributes from the previous Browsing Context still you won't be able to pass those attributes as a HOOK to the WebDriver.

更简洁的方法是调用 webdriver.quit(),然后跨越一个新的 Browsing Context.

A cleaner way would be to call webdriver.quit() and then span a new Browsing Context.

围绕将WebDriver 重新连接到现有的正在运行的浏览上下文 进行了大量讨论和尝试.在讨论中 允许 webdriver 附加到正在运行的浏览器 Simon Stewart [Creator WebDriver] 明确提到:

There had been a lot of discussions and attempts around to reconnect WebDriver to an existing running Browsing Context. In the discussion Allow webdriver to attach to a running browser Simon Stewart [Creator WebDriver] clearly mentioned:

  • 重新连接到现有的浏览上下文是浏览器特有的功能,因此不能以通用方式实现.
  • 使用 ,可以遍历操作系统中打开的窗口并找到要附加到的正确 IE 进程.
  • 需要在特定模式和配置下启动, 这实际上意味着附加到正在运行的实例在技术上是不可能的.
  • Reconnecting to an existing Browsing Context is a browser specific feature, hence can't be implemented in a generic way.
  • With internet-explorer, it's possible to iterate over the open windows in the OS and find the right IE process to attach to.
  • firefox and google-chrome needs to be started in a specific mode and configuration, which effectively means that just attaching to a running instance isn't technically possible.

<小时>

tl;博士

webdriver.firefox.use现有未实现

这篇关于如何重新连接到 webdriver 使用 selenium 打开的浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆