Technology, Tutorial, Ubuntu

Overcoming Painful Setup for Selenium with Python on Ubuntu

EDIT 191118
I realized that I need to execute the script below every time my computer reboots so my current workflow is to leave the command commented out in script and then run it before I begin. You can probably run it with the script too? This one: export PATH=$PATH:/home/user/path/to/browser_drivers_for_automation

I had the following continual painfull errors:

  1. selenium.common.exceptions.WebDriverException: Message: ‘my_folder_name’ executable may have wrong permissions.
  2. selenium.common.exceptions.WebDriverException: Message: ‘Automation_Browser_Drivers’ executable needs to be in PATH.

To be transparent, I’m not sure which if any of these steps happened first, or whether it matters, but I’ll give you both in case it helps and in the order I did:

For my setup, since I plan to mess around with automation long term I wanted to have all my different browser drivers in one folder so I can kind of ‘containerize’ them and always know where they are, and update them accordingly. So, I made a directory called ‘browser_drivers_for_automation”

In that, I downloaded all the executables (go figure out how to do that if you want from Selenium page)

The following is the seemingly standard ‘trial run’ to make sure you are setup and working. I definitely recommend not moving forward until you have this trial run going, as well!

from selenium import webdriver

ffpath = '/home/username/path/to/browser_drivers_for_automation'
browser = webdriver.Firefox(ffpath)

browser.get("http://www.python.org")

First, try that. If it runs, awesome, but if you’re like me probably it won’t, HA

So then first, make sure this ‘browser_drivers_for_automation’ directory is listed in your Ubuntu PATH. If you’re like me I didn’t even know what that was but it seems (short version of the story) that this is the part of Ubuntu that says ‘any directory path in here, if you execute a file, I will allow it”

So do this in a terminal:

export PATH=$PATH:/home/user/path/to/browser_drivers_for_automation

not sure what this next one does but I did it so you might as well join me!

source ~/.profile

So now if you do echo $PATH in your terminal you should see your folder listed.

Now, try the above Selenium trial run again. If it works, great. If not, like me, then do this step:

Navigate to your Browser_drivers_for_automation directory and make your driver executable. In my example here i’m using the firefox geckodriver, but you can do this to any/all drivers in here.

sudo chmod +x geckodriver

See if that works. If it does, the browser will open and you should be good to go now.

Hope this helps

Thanks to all those people answering questions in stackoverflow as usual! 🙂

Tagged , ,

Leave a Reply

Your email address will not be published. Required fields are marked *