HENNGE / arsenic

Async WebDriver implementation for asyncio and asyncio-compatible frameworks
Other
349 stars 52 forks source link

SessionStartError: invalid argument: firefoxOptions is not the name of a known capability or extension capability #132

Closed lintyflent closed 2 years ago

lintyflent commented 2 years ago
...
        GECKODRIVER = None
        if sys.platform.startswith('win'):
            GECKODRIVER = './geckodriver/geckodriver.exe'
        else:
            GECKODRIVER = './geckodriver/geckodriver'

        service = services.Geckodriver(binary=GECKODRIVER)
        browser = browsers.Firefox(firefoxOptions={
            'args': ['-headless']
        })
        async with get_session(service, browser) as session:
            await session.get(text)
            new_= await session.wait_for_element(5, 'html')
            await f_bot.send_message(
                user_id,
                new_
            )
...
  File "/home/user/.local/lib/python3.9/site-packages/aiogram/dispatcher/dispatcher.py", line 388, in _process_polling_updates
    for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
  File "/home/user/.local/lib/python3.9/site-packages/aiogram/dispatcher/dispatcher.py", line 225, in process_updates
    return await asyncio.gather(*tasks)
  File "/home/user/.local/lib/python3.9/site-packages/aiogram/dispatcher/handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "/home/user/.local/lib/python3.9/site-packages/aiogram/dispatcher/dispatcher.py", line 246, in process_update
    return await self.message_handlers.notify(update.message)
  File "/home/user/.local/lib/python3.9/site-packages/aiogram/dispatcher/handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "/home/user/.../my_file.py", line 47, in _
    async with get_session(service, browser) as session:
  File "/home/user/.local/lib/python3.9/site-packages/arsenic/__init__.py", line 16, in __aenter__
    self.session = await start_session(self.service, self.browser, self.bind)
  File "/home/user/.local/lib/python3.9/site-packages/arsenic/__init__.py", line 29, in start_session
    return await driver.new_session(browser, bind=bind)
  File "/home/user/.local/lib/python3.9/site-packages/arsenic/webdriver.py", line 55, in new_session
    raise SessionStartError(
arsenic.errors.SessionStartError: invalid argument: firefoxOptions is not the name of a known capability or extension capability

The code is taken from the documentation. https://arsenic.readthedocs.io/en/latest/reference/supported-browsers.html#headless-firefox.

How then to make Headless Firefox correctly?

dimaqq commented 2 years ago

off the top of my head, "moz:firefoxOptions" but I'm not sure about the API

dimaqq commented 2 years ago

I hope you can massage this into the API somehow: https://github.com/HDE/arsenic/blob/1ab34d69a8d99a0cb877d93cefc42b2644f743cf/tests/conftest.py#L40-L45

lintyflent commented 2 years ago

I hope you can massage this into the API somehow:

https://github.com/HDE/arsenic/blob/1ab34d69a8d99a0cb877d93cefc42b2644f743cf/tests/conftest.py#L40-L45

Unfortunately, I do not know how to insert it.

lintyflent commented 2 years ago

Is this a bug in the documentation?

dimaqq commented 2 years ago

I guess it used to be firefoxOptions at some point, and then Firefox/geckodriver changed it to moz:firefoxOptions. I've made #135 to fix.