由于某些未知原因,我的浏览器打开远程服务器的测试页面非常缓慢。所以我在想,如果我可以在退出脚本后重新连接到浏览器,但不执行 webdriver.quit()
这将使浏览器保持打开状态。它可能是一种 HOOK 或网络驱动程序句柄。
我查了selenium API 文档但没有找到任何函数。
我正在使用 Chrome 62、x64、windows 7、selenium 3.8.0。
无论问题能否解决,我将不胜感激。
最佳答案
否,退出脚本后您无法重新连接到之前的网络浏览 session 。即使您能够从之前的浏览上下文中提取Session ID
、Cookies
和其他 session 属性,您仍然无法将这些属性作为 HOOK 传递给 WebDriver .
更简洁的方法是调用 webdriver.quit()
,然后跨越新的浏览上下文。
深入探讨
围绕将WebDriver重新连接到现有正在运行的浏览上下文进行了很多讨论和尝试。讨论中Allow webdriver to attach to a running browser Simon Stewart [Creator WebDriver] 明确提到:
<小时/>
- 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;博士
关于python-3.x - 如何使用selenium重新连接到webdriver打开的浏览器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54420718/