Search code examples
pythonpython-3.xseleniumselenium-webdrivergeckodriver

selenium working as line-by-line but not in a script


my python script in upper left corner , error message in the middle , when i execute line by line in the lower left corner, the right half is geckodriver log

Im trying to run python script using selenium module to make basic automated youtube search. I get the error show in the middle picture when I write the script as a whole but when I write the code line-by-line it works perfectly . I tried reinstalling gecko and firefox but didnt work . how i installed gecko: 1)un-tar file 2) make file executable 3)mv file to usr/local/bin ... Geckodriver 26.0.0 Firefox 75.0 ubuntu 19.10 vim 8.2


Solution

  • The log is pretty clear about the error, you cannot run geckodriver as root, you've to run it under a different user, which you can do using sudo -H -u, i.e.:

    chown someuser:someuser /path/to/script.py
    sudo -H -u someuser python /path/to/script.py