0

A simlar issue was raised in this post and I have followed the approach suggested by @J3soon, the following code is trying to install an extension to my remote webdrive to bypass captcha.

@contextmanager
def get_selenium_driver(selenium_command_executor):

    driver = webdriver.Remote(
        command_executor=selenium_command_executor, options=webdriver.FirefoxOptions())

    addon = webdriver.Firefox.install_addon(driver, "extension/captcha.xpi")

    try:
        yield driver

    finally:
        driver.delete_all_cookies()
        webdriver.Firefox.uninstall_addon(driver, addon)
        driver.quit()

However, I have been getting this error suggesting it cannot find the path for my extension but I have double checked it is correct, the extension folder is kept at the same level as the main.py file.

2023-03-06 00:11:54 [2023-03-06 00:11:54] [INFO] Starting...
2023-03-06 00:11:56 [2023-03-06 00:11:56] [ERROR] Got error
2023-03-06 00:11:56 Traceback (most recent call last):
2023-03-06 00:11:56   File "/usr/src/app/main.py", line 107, in <module>
2023-03-06 00:11:56     with get_selenium_driver(args.selenium_executor) as driver:
2023-03-06 00:11:56   File "/usr/local/lib/python3.9/contextlib.py", line 119, in __enter__
2023-03-06 00:11:56     return next(self.gen)
2023-03-06 00:11:56   File "/usr/src/app/main.py", line 35, in get_selenium_driver
2023-03-06 00:11:56     addon = webdriver.Firefox.install_addon(driver, "extension/captcha.xpi")
2023-03-06 00:11:56   File "/usr/src/app/.venv/lib/python3.9/site-packages/selenium/webdriver/firefox/webdriver.py", line 262, in install_addon
2023-03-06 00:11:56     with open(path, 'rb') as file:
2023-03-06 00:11:56 FileNotFoundError: [Errno 2] No such file or directory: 'extension/captcha.xpi'
2023-03-06 00:11:56 [2023-03-06 00:11:56] [INFO] Done

Is there something I'm missing here? Thanks!

I have tried using r'path/to/extension' as the extension path but that hasn't worked either.

mg1166
  • 11
  • 1
  • 1
    `path` is looking for an absolute path, not a relative path. so add complete path vs relative path `extension/captcha.xpi` – simpleApp Mar 06 '23 at 02:02

0 Answers0