0

I installed the selenium module with pip installer. Then I tried to make the code to open firefox, then open a new tab to go to google.

Code:

from selenium import webdriver 

driver = webdriver.Firefox()
driver.get("http://www.google.com")

The expected result should have opened firefox and then go to google.com.

But what actually happened was the program didn't produce any error, it just didn't open firefox, and the screen wasn't frozen either.

atline
  • 28,355
  • 16
  • 77
  • 113
  • 2
    Your code seems fine, can you provide python version, firefox version and geckodriver version – Nic Laforge May 23 '19 at 01:46
  • Did you install geckodriver and add the location to your environment variables? You need to install geckodriver separately from firefox to use selenium with the firefox browser, and to initialize the browser without specifying geckodriver location you have to add the location to the path. – SweepingsDemon May 23 '19 at 02:27

1 Answers1

1
  1. Download a matching version of Geckodriver and unpack the geckodriver.exe to the location where current user can execute programs from (normally it's any place inside your home folder)
  2. Amend your code to include the location of the aforementioned geckodriver like:

    driver = webdriver.Firefox(executable_path="/path/to/the/geckodriver/binary")
    
  3. If this doesn't help - provide the path to the Firefox executable as well:

    driver = webdriver.Firefox(executable_path="/path/to/the/geckodriver/binary", firefox_binary="/path/to/firefox/binary")
    

Instead of steps 2 and 3 you can add both firefox and geckodriver to your OS PATH

References:

Dmitri T
  • 159,985
  • 5
  • 83
  • 133