Reputation: 1
I'm trying selenium webdriver for the first time. I've update to Python 3.6 and I reinstalled selenium as well. Trying to open a basic webpage has gone wrong already. Here is the code:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.python.org")
It's very basic yet it still isn't working. It's throwing a few errors that are beyond my skill of interpreting. Of course, I tried googling the issue and nothing seemed to help. I'd appreciate any input. These are the errors:
Traceback (most recent call last):
File "C:\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Python36\lib\subprocess.py", line 707, in __init__restore_signals, start_new_session)
File "C:\Python36\lib\subprocess.py", line 990, 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 "C:/Users/Will Pickard/PycharmProjects/Basics/Webdriver.py", line 3, in <module>
driver = webdriver.Firefox()
File "C:\Python36\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 140, in __init__
self.service.start()
File "C:\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 81, 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 0x03801170>>
Traceback (most recent call last):
File "C:\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 173, in __del__
self.stop()
File "C:\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 145, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
Upvotes: 0
Views: 3943
Reputation: 186
You would have to install geckodriver ( for gecko browsers like firefox after v47 ) or chromedriver ( for chrome browser). Once installed, you should be able to execute code using below mentioned configuration.
You can set DesiredCapabilities as FIREFOX and point to driver binary file. You should be able to configure driver with these capabilities and retrieve desired page.
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['binary'] = '/usr/local/bin/geckodriver'
driver = webdriver.Firefox(capabilities=firefox_capabilities)
driver.get("http://www.python.org")
Alternatively, if you are not sure that newer version of Firefox is being used, then you can do something like this without setting DesiredCapabilities:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
driver = webdriver.Firefox(firefox_binary=FirefoxBinary('/usr/local/bin/geckodriver'))
driver.get("http://www.python.org")
Upvotes: 0
Reputation: 324
Since a couple of versions ago, Selenium stopped providing native support for Firefox, and now relies on using an external browser driver for control. Download the available gecko webdriver and use the following code:
from selenium import webdriver
ff = "/path/to/geckodriver"
driver = webdriver.Firefox(executable_path=ff)
Upvotes: 1