I have been trying to use Arsenic to make asynchonous web calls with a webdriver, and I've hit a roadblock. I can get the service (Geckodriver) all set up, however I cannot figure out the proper way to tell Arsenic where the location of the Browser (Firefox) binary is. The documention is sparse and, as near as I can tell, does not touch on this.
Here's how I did Geckodriver:
from arsenic import get_session
from arsenic.browsers import Firefox
from arsenic.services import Geckodriver
service = Geckodriver()
service.binary = "\\path\\to\\binary.exe"
Right after that, I tried just
browser = Firefox()
However when I called async with get_session(service, browser):
I got this error:
Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
Because I don't know what the default location is and I'm not using a command line, I tried setting the moz.firefoxOptions.binary
capability:
browser = Firefox()
browser.capabilities["moz:firefoxOptions.binary"] = "\\PATH\\TO\\BINARY"
After getting the session with the new browser, I get the error Unrecognised option moz:firefoxOptions.binary
so now I really don't know what it wants from me, and I would appreciate any help.
Thank you!
it seems Arsenic is not being updated for a while according to this comment https://github.com/HENNGE/arsenic/pull/142#issuecomment-1552265741
I had some problems with documentation and just opened a issue to this repository and someone answered quickly. You can check this link too https://arsenic.readthedocs.io/en/latest/tutorials/helloworld.html#writing-the-script It has an example of usage.
import asyncio
import sys
from arsenic import get_session, keys, browsers, services
if sys.platform.startswith('win'):
GECKODRIVER = './geckodriver.exe'
else:
GECKODRIVER = './geckodriver'
async def hello_world():
service = services.Geckodriver(binary=GECKODRIVER)
browser = browsers.Firefox()
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()
There is this library that is an option to Arsenic and it is in constant evolution
https://pypi.org/project/caqui/#description
It does not need the WebDriver binary path to work