简体   繁体   中英

Running ChromeDriver or FirefoxDriver on Selenium without it's GUI (headless mode)

JAVA (selenium code snippet):

    manageDriver();
    WebDriver driver = new ChromeDriver();
    driver.get(url);
    driver.manage().timeouts().implicitlyWait(3+r, TimeUnit.SECONDS);

This is enough to create a ChromeDriver window, which is very annoying for my clients. Is there a way I can make ChromeDriver run without the GUI?

EDIT: I have seen something called xvfb, not sure what it is. Could I use it to make my firefoxDriver or chromeDriver headless?

You need a X server. Follow these steps: Install xvfb:

sudo apt-get install xvfb

Then run it with a display number. For ex 40:

Xvfb :40 &

Run client:

Xvfb :40 -screen 0 1024x768x24 -extension RANDR &

Export Display:

export DISPLAY=:40

Start run your scripts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM