Reputation: 679
im trying to execute some selenium with unittest scripts but i get the following error
Starting at: "Sat Dec 07 14:43:17 2013"
E
======================================================================
ERROR: test_template (__main__.ManageTemplates)
----------------------------------------------------------------------
Traceback (most recent call last):
File "template.py", line 70, in tearDown
self.driver.quit()
File "C:\Program Files (x86)\Python27\lib\site-packages\selenium-2.38.1-py2.7.egg\selenium\webdriver\firefox\webdriver.py", line 66, in quit
RemoteWebDriver.quit(self)
File "C:\Program Files (x86)\Python27\lib\site-packages\selenium-2.38.1-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 454, in quit
self.execute(Command.QUIT)
File "C:\Program Files (x86)\Python27\lib\site-packages\selenium-2.38.1-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 162, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\Program Files (x86)\Python27\lib\site-packages\selenium-2.38.1-py2.7.egg\selenium\webdriver\remote\remote_connection.py", line 350, in execute
return self._request(url, method=command_info[0], data=data)
File "C:\Program Files (x86)\Python27\lib\site-packages\selenium-2.38.1-py2.7.egg\selenium\webdriver\remote\remote_connection.py", line 381, in _request
self._conn.request(method, parsed_url.path, data, headers)
File "C:\Program Files (x86)\Python27\lib\httplib.py", line 973, in request
self._send_request(method, url, body, headers)
File "C:\Program Files (x86)\Python27\lib\httplib.py", line 1001, in _send_request
self.putrequest(method, url, **skips)
File "C:\Program Files (x86)\Python27\lib\httplib.py", line 871, in putrequest
raise CannotSendRequest()
CannotSendRequest
----------------------------------------------------------------------
Ran 1 test in 766.686s
FAILED (errors=1)
the errors accure in template.py at line 70 in tearDown() function, which is a default unittest function autogenerated with Selenium-IDE
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
EDIT:
This Problem happened when i updated Firefox to 26, even when i updated to selenium 2.39.0 the problem didnt go away
Source:
import unittest
from os import path
from config import config
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from PyWebBotClass import PyWebBot
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from os import listdir, environ
from os.path import isfile, join
import time
class ManageReceivers(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(10)
self.base_url = config['baseurl']
self.verificationErrors = []
self.accept_next_alert = True
def setup_bot(self, f):
self.bot = PyWebBot(self.driver, path.join(config['configs'],f))
self.bot.set_LogPath(config['LogPath'])
self.bot.set_ScreenshotPath(config['screenshots'])
self.bot.set_ConfigBaseURL(config['baseurl'])
def test_receiver_profile(self):
self.imported = False
for f in listdir(config['configs']):
if isfile(join(config['configs'],f)):
self.setup_bot(f)
if not self.imported:
self.bot.gotourl('csv2db/import_db_1')
self.imported = True
self.bot.goto('login')
self.bot.JS__fillform('login')
self.bot.goto('receiver_profile')
self.bot.JS__fillform('receiver_profile')
try:
self.bot._driver.execute_script("var e = $('.icon-zoom-in'); e[e.length-1].click()")
except:
print "unable to access selector id = view"
pass
try:
self.bot._driver.execute_script("var e = $('.icon-pencil'); e[e.length-1].click()")
except:
print "unable to access selector id = edit"
pass
self.bot.JS__fillform('receiver_profile')
self.bot.goto('logout')
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert.text
finally: self.accept_next_alert = True
@classmethod
def setUpClass(cls):
environ['NO_PROXY'] = '127.0.0.1' # IP-address of Jenkins server
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == '__main__':
print('Starting at: "%s"' % time.asctime())
unittest.main()
print('Finished at: "%s"' % time.asctime())
Upvotes: 11
Views: 3142
Reputation: 680
From what I can tell, this error is caused by the browser being shut down/killed/crashing and selenium being unable to handle the response that comes back (empty response). I included the details here:
How to deal with sporadic BadStatusLine, CannotSendRequest errors in python WebDriver
But it's a pretty common situation where firefox versions and selenium versions are incompatible. I would just pick the most stable versions and stick to those.
Upvotes: 1
Reputation: 27574
I was also receiving CannotSendRequest() errors when running Selenium 2.39.0 with Firefox 26 on Python 2.7.0 (Windows 8 OS). I resolved the problem by downgrading to Selenium 2.35.0:
pip uninstall selenium
pip install selenium==2.37.0
Running those commands installed 2.35.0. To verify:
import selenium
print selenium.__version__
I then downloaded Firefox 25.0.1 and told Selenium to load that version with the following lines of code:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)
Check which version of Firefox is loading:
from selenium import webdriver
driver = webdriver.Firefox()
print driver.capabilities['version']
And so far the error has not resurfaced.
Upvotes: 0
Reputation: 679
i solved the problem in this way
Get a portable version of Firefox from here (get a version which was working with you for example i got Firefox version 23) and extract it to specific directory
import os
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary(os.path.join('Pathto','FirefoxPortable','FirefoxPortable.exe'))
driver = webdriver.Firefox(firefox_binary=binary)
this has been tested with selenium 2.37.2
and 2.39.0
Enjoy!
Upvotes: 1
Reputation: 471
You can try this code:
from os import environ
And inside your test-case class:
@classmethod
def setUpClass(cls):
environ['NO_PROXY'] = '127.0.0.1' # IP-address of Jenkins server
Probably, I had a similar problem: Django Jenkins raises WebDriverException when processed to Selenium server
Upvotes: 0
Reputation: 14279
Not sure which sub-version of selenium 2.38 you tried, but this issue seems to be fixed in 2.38.4. Here is the issue link
Upvotes: 0