PhantomJを使用する必要はありません。 PhantomJsはあまり保守的ではありません。 chromedriverはヘッドレスモードで使用できます。
あなただけの以下のようにヘッドレスのようなオプションを追加する必要があります: - :まだあなたがphantomjsを使用する場合は一方で
System.setProperty("webdriver.chrome.driver","D:\\Workspace\\JmeterWebdriverProject\\src\\lib\\chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get("https://google.com");
以下の完全なコードを見つけてください
chromeOptions.addArguments("--headless");
。その後、最初のダウンロードは場所を下方からバイナリphantomjs: -
http://phantomjs.org/download.html
は今のコードの下に使用します。 -
System.setProperty("phantomjs.binary.path","D:\\Workspace\\JmeterWebdriverProject\\src\\lib\\phantomjs\\phantomjs.exe");
DesiredCapabilities capabilities = null;
ArrayList<String> cliArgsCap = new ArrayList<String>();
capabilities = DesiredCapabilities.phantomjs();
cliArgsCap.add("--web-security=false");
cliArgsCap.add("--ssl-protocol=any");
cliArgsCap.add("--ignore-ssl-errors=true");
capabilities.setCapability("takesScreenshot", true);
capabilities.setJavascriptEnabled(true);
capabilities.setCapability(
PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
capabilities.setCapability(
PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS,new String[] { "--logLevel=2" });
driver = new PhantomJSDriver(capabilities);
driver.get("https://www.google.co.in/");
が、それはあなたを助けることを願っています:)
は、なぜあなたはHtmlUnitDriverを使いたいですか? –
@ TarunLalwaniこれは、firefoxよりも少ないリソースを使用するので – Mit94
PhantomJSを使用する方が良い。 'HtmlUnitDriver'はテストに最適なドライバではありません。 –