使用python中的selenium连接到一个已经运行的chrome实例 [英] Connect to an already running instance of chrome using selenium in python
问题描述
我在使用硒扩展启动它时遇到了一个问题。我登录了一个问题
https://code.google。 com / p / chromedriver / issues / detail?id = 508
对于解决方案,我打算启动chrome而不是启用所需的扩展,它使用硒。
但我无法如此。
任何人都可以在这个问题上提供帮助,因为d = webdriver.Chrome()总是启动一个新的chrome实例。
我想连接到一个已经运行的chrome实例。
**在python selenium中重新连接驱动程序**
这适用于所有驱动程序。
1.打开驱动程序
driver = webdriver.Firefox()
-
从驱动程序对象中提取到session_id和_url。
url = driver.command_executor._url#http://127.0 .0.1:60622 / hub
session_id = driver.session_id#'4e167f26-dc1d-4f51-a207-f761eaf73c31'
3.使用这两个参数连接到您的驱动程序。
driver = webdriver.Remote(command_executor = url,desired_capabilities = {})
driver.session_id = session_id
-
然后您又连接到您的驱动程序。
driver.get ( http://www.mrsmart.in )
I am facing an issue with chrome while launching it with extensions using selenium. I have logged an issue https://code.google.com/p/chromedriver/issues/detail?id=508
For a workaround I am planing to launch chrome than enable required extension, after this connect to it using selenium.
But I am unable to so so. Can anyone help in this matter as d=webdriver.Chrome() always launches a new chrome instance. I want to connect to an already running instance of chrome.
**Reconnect to a driver in python selenium **
This is applicable on all drivers.
1. open a driver
driver = webdriver.Firefox()
extract to session_id and _url from driver object.
url = driver.command_executor._url #"http://127.0.0.1:60622/hub" session_id = driver.session_id #'4e167f26-dc1d-4f51-a207-f761eaf73c31'
3.Use these two parameter to connect to your driver.
driver = webdriver.Remote(command_executor=url,desired_capabilities={})
driver.session_id = session_id
And you are connected to your driver again.
driver.get("http://www.mrsmart.in")
这篇关于使用python中的selenium连接到一个已经运行的chrome实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!