How to use/attach an existing browser using Selenium?

喜你入骨 提交于 2019-11-27 08:56:35

This is a duplicate answer **Reconnect to a driver in python selenium ** This is applicable on all drivers. 1. open a driver

driver = webdriver.Firefox()

2. 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")
bpk
  1. Run a Webdriver first

    driver = new FirefoxDriver();

  2. Now run a RemoteWebdriver

    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    driver = new RemoteWebDriver(new URL("http://localhost:7055/hub"),capabilities);

The RemoteWebdriver will attach to the first browser window running Webdriver and it will not create a new window.


Note: Run Webdriver (1) and RemoteWebdriver (2) in separate programs one-by-one).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!