Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selenium wont work with Firefox or Chrome

I am trying to learn python web scraping, but I cannot get selenium to work with either browser.

from selenium import webdriver
browser = webdriver.Firefox()

This is all the code I have and I get this for a error.

Traceback (most recent call last):
  File "C:\Users\tjhall\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Users\tjhall\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 950, in __init__
    restore_signals, start_new_session)
  File "C:\Users\tjhall\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1220, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "H:\codingpractice\python\python challenge.com.py", line 2, in <module>
    browser = webdriver.Firefox()
  File "C:\Users\tjhall\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 135, in __init__
    self.service.start()
  File "C:\Users\tjhall\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x00A11350>>
Traceback (most recent call last):
  File "C:\Users\tjhall\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
    self.stop()
  File "C:\Users\tjhall\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
    if self.process is None:
AttributeError: 'Service' object has no attribute 'process'

I have tried everything I can find on the internet from adding the path to the code

from selenium import webdriver
browser = webdriver.Firefox("C:\Program Files (x86)\Mozilla Firefox\firefox.exe")

to adding it the the PATH in my environment variables. I can't seem to figure this out...

like image 537
AutomateMyJob Avatar asked Nov 05 '16 10:11

AutomateMyJob


People also ask

Why my Selenium is not working?

This is because you don't have the Chromedriver. Go to the ChromeDriver [downloads page] (https://chromedriver.chromium.org/downloads). Download the correct version as per your browser version. As an argument,pass executable_path=r'path/to/chromedriver.exe' in driver = webdriver.

Which browser Selenium does not support?

Where possible, WebDriver drives the browser using the browser's built-in support for automation. Since all the driver implementations except for Internet Explorer are provided by the browser vendors themselves, they are not included in the standard Selenium distribution.

Does Selenium work with Firefox?

Selenium IDE is an integrated development environment for Selenium tests. It is implemented as a Firefox extension, and allows you to record, edit, and debug tests.

Which version of Selenium is compatible with Firefox?

Clients. Selenium users must update to version 3.11 or later to use geckodriver. Other clients that follow the W3C WebDriver specification are also supported.


1 Answers

For both Firefox and Chrome you now need to download geckodriver / chromedriver.These drivers are necessary to communicate between your installed browser and selenium. So you need:

  • Install selenium for python (pip install selenium)
  • Download drivers for the browser you want to use (chromedriver, geckodriver, operadriver etc)
  • Install the browser you want to use on your system (probably already have this)

Now you can add the geckodriver to your path as metioned in this anwser. Or you can set it up directly in your code like this:

Chome: driver = webdriver.Chrome(executable_path='/path/to/chromedriver.exe')

Firefox: driver = webdriver.Firefox(executable_path='/opt/geckoDriver/geckodriver.exe')

like image 185
pagep Avatar answered Oct 21 '22 07:10

pagep