Python Selenium 2.39 and Firefox 26
Asked Answered
P

5

11

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())
Proportional answered 8/12, 2013 at 0:5 Comment(9)
Have you tried self.driver.close() instead of .quit()? I'm not sure the difference between these two methods - give it a try :)Dismast
I started seeing the same a few days ago. Solution: downgrade to selenium 2.37.0Holograph
i tested the same program with selenium 2.35 and Firefox 23, it works fine, but after updating firefox i started seeing problems (not the same as here) too, so i updated seleniums to 2.38 and started seeing the same problem in the middle of the test firefox hangs and responds no more then it crushesProportional
I tried to duplicate your problem (Python 2.7, Selenium 2.39, Firefox 26) with my own Selenium IDE-generated script, but I don't get the error. Can you post the entire script? (If it's large you can use pastebin.com)Hardunn
in short tests the error doesnt appear but in long tests (> 4 minutes) firefox crashes: i made different tests and measured the time, it doesn't break at specific piece of code but at a specific time which range between 3 to 4 minutesProportional
selenium 2.37.0 works ok for me with Firefox 26, while 2.39.0 doesn't.Astor
unfortunately it's also not working me, short/simple tests work fine with 2.37 and 2.39 but my tests are long and complex, tests should fill many forms, submit them, visit many links, execute many javascripts. those tests were working 100% with older version of Firefox (last tested on Firefox 23) ah yeah and by the way they also work on Chromedriver, but i don't like Chromedriver because it's not official!Proportional
Hmm, strange, my selenium tests for django-dash (github.com/barseghyanartur/django-dash/blob/master/src/dash/…) work fine and I do fill forms, submit them, visit links and JavaScript is also taken into consideration. I use Python selenium (pypi.python.org/pypi/selenium/2.37.0). Firefox version 26 (Ubuntu 12.04 LTS).Astor
Yesterday I was seeing the same issue OP reported. Upgraded to Selenium 2.40 and Firefox 28 and I am able to run a full suite with no issues.Cirilla
P
1

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!

Proportional answered 26/1, 2014 at 23:36 Comment(0)
P
1

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.

Parted answered 17/12, 2014 at 17:6 Comment(0)
H
0

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

Henryson answered 23/12, 2013 at 16:19 Comment(0)
S
0

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

Seditious answered 26/12, 2013 at 2:38 Comment(1)
didn't help, i'm using web2py and no DjangoProportional
K
0

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.

Ketty answered 27/1, 2014 at 16:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.