0

I am currently reading Automate the Boring Stuff with Python and trying to learn how to use Selenium. For now, I am just trying to open a webpage and can't even get that to work. I know there are easier ways to launch a webpage with python, but my goal is to work with the webpage content later, so that is why I am using selenium.

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.python.org")

When I run this code, it does successfully launch Firefox but it does not open the web page I specified. This error is also returned.

Traceback (most recent call last):
  File "/Users/lbor/Desktop/se.py", line 2, in <module>
    driver = webdriver.Firefox()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 80, in __init__
    self.binary, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 108, in _wait_until_connectable
    % (self.profile.path))
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: /var/folders/4c/gsw7v5b118j406zxj3lxctt40000gn/T/tmp_dgwff4s If you specified a log_file in the FirefoxBinary constructor, check it for details.

I don't understand what this problem is or how to go about fixing it. I am running OS 10.12.5, Python 3.6, Selenium 2.53.6, Firefox 53.0.3. As for the geckodriver, I don't know what that is or how to install it.

Lmorj
  • 41
  • 1
  • 2
  • 5

2 Answers2

1

You can download geckodriver from here.

After that, you need to load it up, using:

geckodriver = os.path.dirname(os.path.realpath(__file__)) + "/geckodriver"

drv = webdriver.Firefox(geckodriver)
Adeel Ahmad
  • 1,033
  • 1
  • 11
  • 24
0

You can install geckodriver here, by selecting the appropriate version for your computer:

https://github.com/mozilla/geckodriver/releases

Then, in your code, you pass the full path for the location of the geckodriver on your computer to the Firefox method:

browser = webdriver.Firefox(executable_path="/Users/username/Location/geckodriver")

browser.get("https://google.com") #this will load the the google homepage. 
#you can specify any page you want here.
Ajax1234
  • 69,937
  • 8
  • 61
  • 102