[Python] trying to run selenium in linux cant find driver

Discussão em 'Python' iniciado por Stack, Setembro 4, 2025.

  1. Stack

    Stack Membro Participativo

    -rwxr-xr-x 1 kyle kyle 6132584 Feb 24 09:27 /usr/local/bin/geckodriver

    echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/kyle/.dotnet/tools


    It is my understanding selenium should be able to find the driver automatically. That does not seem to work for me.

    pip show selenium
    Name: selenium
    Version: 4.18.1


    if I try and run my python script with

    driver = webdriver.Firefox()


    I get

    Message: Unable to obtain driver for firefox using Selenium Manager.


    if I use

    driver = webdriver.Firefox("/usr/local/bin/geckodriver")


    Traceback (most recent call last):
    File "/usr/lib/python3/dist-packages/selenium/webdriver/common/driver_finder.py", line 38, in get_path
    path = SeleniumManager().driver_location(options) if path is None else path
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3/dist-packages/selenium/webdriver/common/selenium_manager.py", line 87, in driver_location
    browser = options.capabilities["browserName"]
    ^^^^^^^^^^^^^^^^^^^^
    AttributeError: 'str' object has no attribute 'capabilities'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/home/kyle/Documents/ElecticityUsage.py", line 181, in <module>
    driver = webdriver.Firefox("/usr/local/bin/geckodriver")
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3/dist-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
    self.service.path = DriverFinder.get_path(self.service, options)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3/dist-packages/selenium/webdriver/common/driver_finder.py", line 40, in get_path
    msg = f"Unable to obtain driver for {options.capabilities['browserName']} using Selenium Manager."
    ^^^^^^^^^^^^^^^^^^^^
    AttributeError: 'str' object has no attribute 'capabilities'

    Continue reading...

Compartilhe esta Página