Randy Tang
Randy Tang

Reputation: 4353

Selenium: how to open a blank Firefox browser

I am trying to write test cases in a Django project with Selenium. The statements used to open a Firefox browser are as follows:

class StudentTestCase(LiveServerTestCase):

    def setUp(self):
        self.browser = webdriver.Firefox()
        self.browser.implicitly_wait(2)

    def tearDown(self):
        self.browser.quit()

However, every time the Firefox browser opens, it tries to connect to https://www.mozilla.org/zh-TW/firefox/42.0/firstrun/learnmore/, which takes a long time downloading a lot of stuff before the browser can be closed (it takes tens of seconds!).

There is a similar question, however, it is a Java solution, instead of a Python/Django one.

So, what's the Python/Django solution about opening a BLANK Firefox browser?

Upvotes: 2

Views: 1179

Answers (1)

Mesut GUNES
Mesut GUNES

Reputation: 7421

You do it by setting a profile with set_preference, see below:

>>> from selenium import webdriver
>>> profile = webdriver.FirefoxProfile();
>>>
>>> profile.set_preference("browser.startup.homepage", "about:blank");
>>> profile.set_preference("startup.homepage_welcome_url", "about:blank");
>>> profile.set_preference("startup.homepage_welcome_url.additional", "about:blank");
>>>
>>> dr = webdriver.Firefox(profile)
>>> dr.title
u''

Upvotes: 2

Related Questions