How to hide Firefox window (Selenium WebDriver)?

前端 未结 14 952
执念已碎
执念已碎 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

    Python

    The easiest way to hide the browser is to install PhantomJS. Then, change this line:

    driver = webdriver.Firefox()
    

    to:

    driver = webdriver.PhantomJS()
    

    The rest of your code won't need to be changed and no browser will open. For debugging purposes, use driver.save_screenshot('screen.png') at different steps of your code or just switch to the Firefox webdriver again.

    On Windows, you will have to specify the path to phantomjs.exe:

    driver = webdriver.PhantomJS('C:\phantomjs-1.9.7-windows\phantomjs.exe')
    

    Java

    Have a look at Ghost Driver: How to run ghostdriver with Selenium using java


    C#

    How to hide FirefoxDriver (using Selenium) without findElement function error in PhantomDriver(headless browser)?

提交回复
热议问题