Can Selenium interact with an existing browser session?

后端 未结 11 987
野性不改
野性不改 2020-11-22 08:47

Does anybody know if Selenium (WebDriver preferably) is able to communicate with and act through a browser that is already running before launching a Selenium Client?

11条回答
  •  执笔经年
    2020-11-22 09:14

    I got a solution in python, I modified the webdriver class bassed on PersistenBrowser class that I found.

    https://github.com/axelPalmerin/personal/commit/fabddb38a39f378aa113b0cb8d33391d5f91dca5

    replace the webdriver module /usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py

    Ej. to use:

    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    
    runDriver = sys.argv[1]
    sessionId = sys.argv[2]
    
    def setBrowser():
        if eval(runDriver):
            webdriver = w.Remote(command_executor='http://localhost:4444/wd/hub',
                         desired_capabilities=DesiredCapabilities.CHROME,
                         )
        else:
            webdriver = w.Remote(command_executor='http://localhost:4444/wd/hub',
                                 desired_capabilities=DesiredCapabilities.CHROME,
                                 session_id=sessionId)
    
        url = webdriver.command_executor._url
        session_id = webdriver.session_id
        print url
        print session_id
        return webdriver
    

提交回复
热议问题