0

I'm using selenium from Python with the Phantomjs webdriver. I'm running both Selenium and my server locally on my laptop. When I run my test:

class TestNotLoggedIn(unittest.TestCase):
    def setUp(self):
        app.config['TESTING'] = True
        app.config['CSRF_ENABLED'] = False

        self.driver = webdriver.PhantomJS()

    def test_frontpage(self):
        driver = self.driver
        driver.get('localhost:5000')
        print driver.page_source

it prints this html source:

<html><head></head><body></body></html>

Whereas, when I go to localhost:5000 in the browser, I get the full source of my page:

!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>MyWebsite</title>etc. etc.

Does anybody know what I'm doing wrong here?

ps. I've tried adding service_args=['--ignore-ssl-errors=true']) as suggested here, but that makes no difference.

Community
  • 1
  • 1
kramer65
  • 50,427
  • 120
  • 308
  • 488
  • Can you try interacting with an element before you grab the page source? It seems that the page has not yet fully loaded. You could trying doing an implicit wait to identify an element and then grab the page source. – Jamie Rees Feb 09 '15 at 09:07

1 Answers1

1

Turns out that PhantomJS needs http:// to also be defined. So for future readers (including myself): when getting the page like this, it works like a charm:

driver.get('http://localhost:5000')
kramer65
  • 50,427
  • 120
  • 308
  • 488