Last Updated: February 25, 2016
·
7.679K
· jonahlyn

Testing HTTP Status Codes (Selenium)

I'm just getting started learning how to use Selenium for testing web apps and I was a bit shocked to find that access to the HTTP status code was not possible (since 2009!).

http://code.google.com/p/selenium/issues/detail?id=141

This seems to get the job done as a workaround:

import urllib2

class MyunmTestCase(unittest.TestCase):

    def test_something(self):
        request = urllib2.urlopen("http://google.com")
        self.assertEqual(request.getcode(), 200)

    ...

Not sure how 'pro' this is but it works for me for now.