简体   繁体   中英

Chromedriver and the Selenium framework - browser window opens as soon as chromedriver is instantiated

I am on a Macbook Pro, and I am using Selenium 2.46.0 for Java and Chromedriver. I only have a main method, as follows:

public static void main(String[] args) {
    System.setProperty("webdriver.chrome.driver", "path/to/driver/")
    WebDriver driver = new ChromeDriver();

For some reason, this alone will start up the browser, with the "starting ChromeDriver" message output in the terminal. Is this the desired behavior? Also, I am not given by terminal back when chromedriver starts (I cannot input regular terminal commands once chromedriver is running; some code from chromedriver must still be executing/blocking etc). How can I prevent chromedriver from starting up automatically, and how can I regain control of my terminal once chromedriver begins?

That's actually an expected behaviour, because Selenium Webdriver needs display.

But you can run it in a headless mode using Xvfb , some good examples:

Unfortunately you can't run Chrome in Mac OS X using Xvfb, but you can easily install something like Vagrant to run it in Ubuntu virtually.

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