Firefox won't open using geckodriver - python

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")

Related

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')

twil python linux errors

I've a raspberry PI whit raspbian. When i try to start a python application whit selenium it give me some errors.
This is the application:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
browser = webdriver.Firefox(executable_path=r'/home/pi/Desktop/geckodriver')
This is errors:
Traceback (most recent call last):
File "uno.py", line 5, in <module>
browser = webdriver.Firefox(executable_path=r'/home/pi/Desktop/geckodriver')
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 160, in __init__
self.service.start()
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/usr/lib/python3.5/subprocess.py", line 676, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1282, in _execute_child
raise child_exception_type(errno_num, err_msg)
OSError: [Errno 8] Exec format error
How can i fix?
An exec error indicates you took the wrong OS file for geckodriver. See the below for all release
https://github.com/mozilla/geckodriver/releases
As of today (27th Jun 2018), you should probably be picking below
https://github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-arm7hf.tar.gz
Also make sure to do
chmod +x /home/pi/Desktop/geckodriver
So that it has executable rights

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).

Python dryscrape "Xvfb does not start" under XQuartz & xvfbwrapper & MacOSX Sierra

Under MacOSX Sierra, and XQuartz 2.7.11, Python 2.7. I was able to install dryscrape and its required other python packages. I've tried quite a few methods to get some simple code working, but I can't seem to get it working. Here is the simple code:
#!/usr/bin/python
#coding: utf-8
import dryscrape
testurl = 'http://avi.im/stuff/js-or-no-js.html'
dryscrape.start_xvfb()
session = dryscrape.Session()
session.visit(testurl)
exit()
You can see it is a simple python script file. It fails on either the start_svfb() or the Session() line. I can post the errors and such, but can I start a discussion on simply what check list should I setup, run, and test to make sure the X11 environment is right? Do I run the script under OS X terminal or XQuartz? What am I missing? etc.?
Thanks in advance, Lucas.
here is the last traceback from python:
Traceback (most recent call last):
File "./fred.py", line 19, in
session = dryscrape.Session()
File "build/bdist.macosx-10.12-intel/egg/dryscrape/session.py", line 22, in __init__
File "build/bdist.macosx-10.12-intel/egg/dryscrape/driver/webkit.py", line 30, in __init__
File "/Library/Python/2.7/site-packages/webkit_server-1.0-py2.7.egg/webkit_server.py", line 230, in __init__
self.conn = connection or ServerConnection()
File "/Library/Python/2.7/site-packages/webkit_server-1.0-py2.7.egg/webkit_server.py", line 507, in __init__
self._sock = (server or get_default_server()).connect()
File "/Library/Python/2.7/site-packages/webkit_server-1.0-py2.7.egg/webkit_server.py", line 450, in get_default_server
_default_server = Server()
File "/Library/Python/2.7/site-packages/webkit_server-1.0-py2.7.egg/webkit_server.py", line 416, in __init__
stderr = subprocess.PIPE)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

In python, selenium module . how to use firefox driver

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().

Categories