In python, selenium module . how to use firefox driver - python

I want to use Selenium's Firefox driver.
But I got the error shown below. Is it possible that Firefox didn't install properly?
------ my source ------
from selenium import webdriver
driver = webdriver.Firefox()
------ my source End------
Here is the error that was returned:
Traceback (most recent call last):
File "test.py", line 4, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python2.7/site-packages/selenium-2.25.0-py2.7.egg/selenium/webdriver/firefox/webdriver.py", line 51, in __init__
self.binary, timeout),
File "/usr/local/lib/python2.7/site-packages/selenium-2.25.0-py2.7.egg/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "/usr/local/lib/python2.7/site-packages/selenium-2.25.0-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 43, in launch_browser
self._start_from_profile_path(self.profile.path)
File "/usr/local/lib/python2.7/site-packages/selenium-2.25.0-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 65, in _start_from_profile_path
env=self._firefox_env).communicate()
File "/usr/local/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/local/lib/python2.7/subprocess.py", line 1228, in _execute_child
raise child_exception
AttributeError: 'NoneType' object has no attribute 'rfind'

I faced the same error but got fixed when I installed firefox. Didn't realise that firefox was not installed. Check it out.

selenium webdriver gives you programmatic access to web content. It drives a real browser, so yes, you need Firefox installed to instantiate webdriver.Firefox().

Related

Firefox won't open using geckodriver

I'm running my scripts through Cygwin and everything was working just fine until I had to reinstall it. Now my script freezes as soon as I try to open the browser, not giving any error. I'm using geckodriver v0.25.0 and firefox 66.0.4. Everything is the same as before as far as I know.
Traceback (most recent call last):
File "t.txt", line 5, in <module>
driver = webdriver.Firefox(executable_path="./geckodriver.exe")
File "/usr/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
self.service.start()
File "/usr/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/usr/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.7/subprocess.py", line 1476, in _execute_child
part = os.read(errpipe_read, 50000)
KeyboardInterrupt
Code used
#!/usr/bin/env python
from selenium import webdriver
driver = webdriver.Firefox(executable_path="./geckodriver.exe")
driver.get("https://inventwithpython.com")

error while exeutiing Selenium Python automation script

I just copied selenium script from web and trying to learn selenium python automation.
Here is the script
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.facebook.com")
While running I got following error
Traceback (most recent call last):
File "C:\Users\hpatel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\hpatel\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 756, in __init__
restore_signals, start_new_session)
File "C:\Users\hpatel\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1155, 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\hpatel\python\PythonLearn\src\Example1.py", line 8, in <module>
driver = webdriver.Firefox()
File "C:\Users\hpatel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 160, in __init__
self.service.start()
File "C:\Users\hpatel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
What is the issue?
I copied geckodriver file to c drive and define the path too.
Just replace this line :
driver = webdriver.Firefox()
To:
driver = webdriver.Firefox(executable_path = r'C:/Users/user***/Downloads/geckodriver-v0.20.1-win64/geckodriver.exe')

Selenium Firefox 56 webdriver via geckodriver results in error: Can not connect to the Service

I am using geckodriver for Firefox and I'm running Python 3 with Selenium. This is my code in the file script.py:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.google.com')
Once I run it with python3 script.py with my terminal, it launches Firefox but simply doesn't load the page, nor does it insert the link in the address bar. My geckodriver is installed at this location: /usr/local/bin/geckodriver.
After waiting for about a minute, I get the following error:
Traceback (most recent call last):
File "script.py", line 3, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 154, in __init__
keep_alive=True)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 151, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 240, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 308, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused
I already searched a lot for fixes but none of them worked.
After I realized, I was using Firefox ESR instead of the normal one, I switched to the normal Firefox version and faced this problem:
Traceback (most recent call last):
File "script.py", line 3, in <module>
driver = webdriver.Firefox(executable_path=r'/root/Downloads/firefox-56.0.1/firefox/firefox')
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 144, in __init__
self.service.start()
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 102, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service /root/Downloads/firefox-56.0.1/firefox/firefox
Which version of Selenium/Geckodriver/Browser are you using?
Anyway, do you set the executable_path:
driver = webdriver.Firefox(executable_path=r'pathTo/geckodriver')
?
EDIT
If you are using:
Selenium version = 3.6.0
Geckodriver version = 0.19.0
Firefox version = 52.4.0
Your problem is Firefox. From GeckoDriver releases, is recommended Firefox 55.0 (and greater).

selenium and web2py from killer-web-development.com doesn't work

I am trying to follow the tutorial on http://killer-web-development.com/section/4/3
and I am running into the error message:
======================================================================
ERROR: setUpClass (test_static_pages.TestHomePage)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Applications/web2py.app/Contents/Resources/applications/tukker/functional_tests.py", line 18, in setUpClass
self.browser = webdriver.Firefox()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 51, in __init__
self.binary, timeout),
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/firefox/extension_connection.py", line 46, in __init__
self.binary.launch_browser(self.profile)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 44, in launch_browser
self._wait_until_connectable()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 86, in _wait_until_connectable
self.profile.path, self._get_firefox_output()))
WebDriverException: Message: 'Can\'t load the profile. Profile Dir: /tmp/tmpXWOMML Firefox output: 1409783847270\taddons.manager\tDEBUG\tLoaded provider scope for resource://gre/modules/addons/XPIProvider.jsm: ["XPIProvider"]\n1409783847271\taddons.manager\tDEBUG\tLoaded provider scope for resource://gre/modules/LightweightThemeManager.jsm: ["LightweightThemeManager"]\n1409783847272\taddons.xpi\tDEBUG\tstartup\n1409783847273\taddons.xpi\tDEBUG\tSkipping unavailable install location app-system-share\n1409783847283\taddons.xpi\tDEBUG\tcheckForChanges\n1409783847286\taddons.xpi\tDEBUG\tNo changes found\nJavaScript error: chrome://browser/content/urlbarBindings.xml, line 674: aUrl is undefined\n'
What is wrong? I am on MacOsX maverics and have installed selenium using macports if that is of any help.
The reason you have problems is because you have a brand new browser and an old selenium.
You need to do two things:
upgrade selenium package to the latest (currently 2.42.1) version
downgrade Firefox to 28 version

python bindings for selenium returns in exception when initiating a Firefox webdriver object

When on windows I want to give a try with the webdriver extension for selenium, I get an error. I installed the python bindings like on the installation page. And then I try to to just the following:
from selenium import webdriver
browser = webdriver.Firefox()
Firefox (15.0) is opened and after that an exception occurs:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\selenium-2.32.0-py2.7.egg\selenium\webdriver\firefox\webdriver.py", line 62, in __init__
desired_capabilities=capabilities)
File "C:\Python27\lib\site-packages\selenium-2.32.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 72, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Python27\lib\site-packages\selenium-2.32.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 114, in start_session
'desiredCapabilities': desired_capabilities,
File "C:\Python27\lib\site-packages\selenium-2.32.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 165, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium-2.32.0-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 152, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: ''
I tried the same without webdriver, with the 1.0 api and then I can open Firefox and go to a specific page, but with the webdriver case I do not have any luck. Has anyone a clue what I do wrong ?
My OS is Windos 7, 64 bit version.
I also tried the same with the latest python bindings from version control, but that has the same error.

Categories