Testing headless firefox using selenium but it is throwing an error
Question: I am trying to test headless firefox using Selenium and the below code is
giving correct result.

    
    
    From a fresh Ubuntu 14.04 install I did the following
    
    sudo apt-get install python-pip firefox xvfb
    pip install selenium pyvirtualdisplay
    useradd testuser
    And then in a python shell:
    
    from selenium import webdriver
    from pyvirtualdisplay import Display
    display = Display(visible=0, size=(800, 600))
    display.start()
    driver = webdriver.Firefox()
    driver.get("http://askubuntu.com")
    print driver.page_source.encode('utf-8')
    driver.quit()
    display.stop()
    

But if the implement the same functionality using a `class` in `Django
test.py` it is not working and throwing an error.

    
    
    class FirefoxHeadlessTestCase(LiveServerTestCase):
        def setUp(self):
            # start display
            self.display = Display(visible=0, size=(1024, 768))
            self.display.start()
            # start browser
            self.driver = webdriver.Firefox()
    
        def tearDown(self):
            # stop browser
            self.driver.quit()
            super(FirefoxHeadlessTestCase, self).tearDown()
    
            # stop display
            self.display.stop()
    
        # check if this test should be skipped
    
        def test_example(self):
            # run tests
            print self.driver.get("http://askubuntu.com").page_source.encode('utf-8')
    

> Error: `print
> self.driver.get("http://askubuntu.com").page_source.encode('utf-8')
> AttributeError: 'NoneType' object has no attribute 'page_source'`

Anyone has an idea where I am going wrong here?


Answer: The problem is with your chaining. Notice that your django code is slightly
different

    
    
     print self.driver.get("http://askubuntu.com").page_source.encode('utf-8')
    

from your other python code

    
    
    driver.get("http://askubuntu.com")
    print driver.page_source.encode('utf-8')  
    

Unfortunately the driver [get](http://selenium-
python.readthedocs.org/api.html#selenium.webdriver.remote.webdriver.WebDriver.get)
method does not return anything so it cannot be changed as done in your django
code. You will need to lines as in your other python code.

