How to hide Firefox window (Selenium WebDriver)?

前端 未结 14 802
执念已碎
执念已碎 2020-11-27 11:08

When I execute multiple test simultaneously, i don\'t want to keep Firefox browser window visible.. I can minimize it using selenium.minimizeWindow() but I don\

相关标签:
14条回答
  • 2020-11-27 11:41

    If you are using KDE Desktop, you can make Firefox Windows to be initially opened being minimized. That made my day to me regarding this problem. Just do the following:

    1. Open Firefox
    2. Click on the Firefox icon on the top left corner of the menu bar -> Advanced -> Special Application Settings...
    3. Go to the "Size & Position" tab.
    4. Click on "Minimized" and choose "Apply Initially" (YES).

    These settings will apply for new Firefox windows from now on and you will not be bothered with pop-ups anymore when running tests with Webdriver.

    0 讨论(0)
  • 2020-11-27 11:42

    If you're using Selenium RC or Remote WebDriver then you can run the browser instance on a remote, or virtual machine. This means that you shouldn't have to worry about hiding the browser windows as they won't be launching on your local machine.

    0 讨论(0)
  • 2020-11-27 11:46

    Just add the following code.

    import os
    os.environ['MOZ_HEADLESS'] = '1'
    driver = webdriver.Firefox()
    
    0 讨论(0)
  • 2020-11-27 11:48

    just add these and it will work if you are using chrome, also useful in firefox

    from selenium.webdriver.chrome.options import Options
    '''option to make driver work background'''
    chrome_options = Options()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable-gpu')
    
    0 讨论(0)
  • 2020-11-27 11:48

    Firefox has a headless mode. If you want to use it, you just have to set it on binary options like this:

    binary = FirefoxBinary("C:/Program Files/Mozilla Firefox/firefox.exe")
    options = webdriver.FirefoxOptions()
    # set headless mode on
    options.set_headless(True) 
    driver = webdriver.Firefox(firefox_binary=binary,options=options)
    
    0 讨论(0)
  • 2020-11-27 11:48

    in options (Firefox options, chrome options )

    set boolean headless to true by calling set_headless method.

    0 讨论(0)
提交回复
热议问题