5

After upgrading to geckodriver I'm unable to reuse my Selenium's sessions. Here's my setup:

I have a start_browser.py script, which launches a Firefox instance and prints a port to connect to, like:

firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
browser = webdriver.Firefox(capabilities=firefox_capabilities)
print browser.service.port
wait_forever()

... and another script, which tries to connect to the existing instance via Remote driver:

caps = DesiredCapabilities.FIREFOX
caps['marionette'] = True
driver = webdriver.Remote(
        command_executor='http://localhost:{port}'.format(port=port),
        desired_capabilities=caps)

But it seems to be trying to launch a new session, and failing with a message:

selenium.common.exceptions.WebDriverException: Message: Session is already started

Is there an ability to just attach to the existing session, like in previous versions of Selenium? Or is this an intended behaviour of geckodriver (hope not)?

4

2 に答える 2

4

よし、誰かがもっとエレガントな解決策を考え出さない限り、ここに簡単な汚いハックがあります:

class SessionRemote(webdriver.Remote):
    def start_session(self, desired_capabilities, browser_profile=None):
        # Skip the NEW_SESSION command issued by the original driver
        # and set only some required attributes
        self.w3c = True

driver = SessionRemote(command_executor=url, desired_capabilities=caps)
driver.session_id = session_id

悪い点は、コマンドがわからないという不平を言ってまだ機能しないことですmovetoが、少なくとも起動したブラウザーに接続します。

更新: geckodriver には現時点でいくつかの機能が欠けているようです。そのため、Firefox を引き続き使用する場合は、古い webdriver をサポートするバージョン (45 でプレイ可能) にダウングレードし、https のようなチケットに注意してください: //github.com/SeleniumHQ/selenium/issues/2285 .

于 2016-06-22T13:00:17.177 に答える