HENNGE / arsenic

Async WebDriver implementation for asyncio and asyncio-compatible frameworks
Other
351 stars 54 forks source link

Failing on Chrome Options when Using Latest Chrome Driver (87.0.4280.20) #102

Closed norsemangrey closed 3 years ago

norsemangrey commented 3 years ago

I'm getting the following error when attempting to run the Demo application with the latest chromedriver:

arsenic.errors.SessionStartError: invalid argument: invalid argument: unrecognized capability: ChromeOptions Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x000002189CBECF70> Unclosed connector connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x000002189CBF6B20>, 170907.187)]'] connector: <aiohttp.connector.TCPConnector object at 0x000002189CBECEE0>

If omitting ChromeOptions it works, but without any capability of setting options.

import asyncio
from arsenic import get_session, keys, browsers, services

async def hello_world():
    service = services.Chromedriver(binary=r'C:\Users\janmar\Downloads\chromedriver.exe')
    browser = browsers.Chrome(ChromeOptions={
        'args': ['--headless', '--disable-gpu']
    })
    async with get_session(service, browser) as session:
        await session.get('https://images.google.com/')
        search_box = await session.wait_for_element(5, 'input[name=q]')
        await search_box.send_keys('Cats')
        await search_box.send_keys(keys.ENTER)
        await asyncio.sleep(10)

def main():
    loop = asyncio.get_event_loop()
    loop.run_until_complete(hello_world())

if __name__ == '__main__':
    main()
dimaqq commented 3 years ago

Can also be reproduced with chromedriver from homebrew ChromeDriver 86.0.4240.22 (398b0743353ff36fb1b82468f63a3a93b4e2e89e-refs/branch-heads/4240@{#378})

dimaqq commented 3 years ago

Apparently the modern syntax is this: {"browserName":"chrome", "goog:chromeOptions":{"args":["--headless","--disable-gpu"]}}

And, if ran as root (e.g. in a container, or CI, then to add "--no-sandbox" to the flags.

dimaqq commented 3 years ago

@norsemanGrey what is the "demo applcation"? Where is its source code? Are you talking about taking https://github.com/HDE/arsenic/blob/main/docs/tutorials/helloworld.py and changing it to use chromedriver instead of geckodriver?

Re: how to pass options, refer to tests here: https://github.com/HDE/arsenic/blob/da8f80dbdda2cf68e6ccce6421d1521faac7d55c/tests/conftest.py#L47-L52

P.S. PRs are welcome! 🙏

norsemangrey commented 3 years ago

@dimaqq yes I was referering to the https://github.com/HDE/arsenic/blob/main/docs/tutorials/helloworld.py code and switched the geckodriver with chromedriver. Sorry for not being specific.

shawnz commented 3 years ago

Thanks dimaqq, based on your advice I changed my code from something like the following:

    browser = browsers.Chrome(ChromeOptions={
        'args': ['--headless', '--disable-gpu']
    })

to look as follows:

    browser = browsers.Chrome(**{"goog:chromeOptions":{
        'args': ['--headless', '--disable-gpu']
    }})

and the issue is resolved for me.

dimaqq commented 3 years ago

Nice, this is already documented in https://github.com/HDE/arsenic/blob/main/docs/reference/supported-browsers.rst