Instance of Firefox WebDriver is not created with selenium python bindings - python

I installed selenium-python bindings and trying to create an instance of firefox web driver
as below
>>> from selenium import webdriver
>>> driver = webdriver.Firefox()
I dont know whats wrong here and its displaying the following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/selenium-2.21.3-py2.7.egg/selenium/webdriver/firefox/webdriver.py", line 51, in __init__
self.binary, timeout),
File "/usr/lib/python2.7/site-packages/selenium-2.21.3-py2.7.egg/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "/usr/lib/python2.7/site-packages/selenium-2.21.3-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 44, in launch_browser
self._wait_until_connectable()
File "/usr/lib/python2.7/site-packages/selenium-2.21.3-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 81, in _wait_until_connectable
self._get_firefox_output())
selenium.common.exceptions.WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: Error: cannot open display: :1100\n'
Can any please let me know how to solve this ..............

The error says"cannot open display: :1100". Are you running it on a remote terminal? Make sure you can type "firefox" at the prompt and have the browser open (that is what Webdriver does - opens Firefox on your system and then trying to connect to it). If you are running it on a remote system, do a web search on connecting to X display remotely.

Related

Unable to Open Chrome Webdriver in Windows 10 [duplicate]

This question already has answers here:
SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81
(37 answers)
Closed 2 years ago.
I want to use chrome webdriver with python and selenium library; however, I'm having problems opening webdriver in python console. It is finding the path and it opens what it seems to be a browser, also it starts a service listening on port #### but when I do
driver.get('http://www.google.com')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'driver' is not defined
it doesn't work... here's the error I'm getting when I open a website
here's the output of opening webdriver
driver = webdriver.Chrome('C:\chromedriver\chromedriver.exe')
DevTools listening on ws://127.0.0.1:52968/devtools/browser/b7b88ebb-e9e1-4726-9d4e-4e3f13990a0a Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\George\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "C:\Users\George\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\George\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\George\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\George\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81
You need your chromedriver.exe to match your current chrome browser's version. To check your chrome version go into your chrome settings and select the about chrome tab. You can find your chrome version there. Then download the chromedriver from here that matches your version. Update the path in your code to this driver and it should work.

selenium script doesn't run in python

Tried executing
from selenium import webdriver
browser=webdriver.Chrome()
browser.get('http://www.google.com')
but doesn't execute and throws error
=RESTART: C:\Users\Phani\AppData\Local\Programs\Python\Python37-32\drive.py =
Traceback (most recent call last):
File "C:\Users\Phani\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\Phani\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "C:\Users\Phani\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1178, 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\Phani\AppData\Local\Programs\Python\Python37-32\drive.py", line 4, in <module>
browser=webdriver.Chrome()
File "C:\Users\Phani\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\Phani\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: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
properly installed selenium using pip install
Please Help!!
This isn't working because you haven't provide path of the chrome driver.WebDriver doesn't know where is the chromedriver path.
driver = webdriver.Chrome("path of the chrome driver Chromedriver.exe")
for example:
from selenium import webdriver
driver = webdriver.Chrome("d:/chromedriver/Chromedriver.exe")
driver.get("https://www.google.com")
You can try Firefox for this purpose:
First Download Geckodriver from here: https://github.com/mozilla/geckodriver/releases/tag/v0.24.0
from selenium import webdriver
fox = webdriver.Firefox(executable_path='/path/to/downloaded/gecko/driver')
fox.get("https://www.google.com")
Same could be done with google chrome :
You can download chrome driver from here:
https://sites.google.com/a/chromium.org/chromedriver/home
No need to setup PATH variable.
I have just fixed the issue. You need to download an updated version of Google Chrome. For instance, my old version was 96 but now it is 101. That is it.

PhantomJS webdriver error code -6

I am running a Python script on a remote server that scrapes periodically a webpage, using PhantomJS as a webdriver in Selenium.
The script stops unexpectedly after running for some hours, throwing the following error:
Traceback (most recent call last):
File "long.py", line 74, in <module>
data = scrape_page_long()
File "long.py", line 19, in scrape_page_long
driver = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/webdriver.py", line 52, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 96, in start
self.assert_process_still_running()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service phantomjs unexpectedly exited. Status code was: -6
I thought at first it had to do with ssl errors (hence the arguments), but it doesn't seem related I think.
Any ideas on what causes this issue?
Your script is never able to scrape the web page, because PhantomJS is not working at all on the server.
If you log into the server and run phantomjs --version you'll see this:
QXcbConnection: Could not connect to display
PhantomJS has crashed. Please read the bug reporting guide at
<http://phantomjs.org/bug-reporting.html> and file a bug report.
Aborted
You can fix this by adding export QT_QPA_PLATFORM=offscreen to your user account's .bashrc, or by adding QT_QPA_PLATFORM=offscreen to the server's /etc/environment.

How to fix WebDriverException: The browser appears to have exited before we could connect? [duplicate]

This question already has answers here:
How to fix Selenium WebDriverException: The browser appears to have exited before we could connect?
(13 answers)
Closed 7 years ago.
In my Linux system I use Firefox, execute my program, the error which I've is:
Traceback (most recent call last):
File "shenma_diff_main_v2.py", line 90, in <module>
browser = webdriver.Firefox(profile)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
self.binary, timeout),
File "/usr/local/lib/python2.7/site-packages/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/webdriver/firefox/firefox_binary.py", line 66, in launch_browser
self._wait_until_connectable()
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 100, in _wait_until_connectable
raise WebDriverException("The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
If I use root execute my program is OK.
This is because you did not set up correctly to run Firefox without GUI.
This is a tutorial that might be helpful
Selenium Headless Automated Testing in Ubuntu
I think the reason is you need to specify the port number, probably xvfb runs on a different port than Firefox
on one terminal:
xvfb :99 -ac
on the another terminal:
export DISPLAY=:99
and run your scrapy program
I am successful without using root

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

Categories