基本的な使い方。
Optionで"test-type"を渡してやらないと--ignore-certificate-errorがどうしたこうしたというエラーがでる。
ソース
test.java
package com.html.sample;
import java.util.Arrays;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class Sample01 {
@BeforeClass
public static void Setup() {
System.setProperty("webdriver.chrome.driver", "./driver/chromedriver");
}
@Test
public void test() {
//WebDriverのオプションを定義
ChromeOptions options = new ChromeOptions();
//--ignore-certificate-errorの出力を防止する
options.addArguments("test-type");
WebDriver driver = new ChromeDriver(options);
//googleにアクセス
driver.get("http://www.google.co.jp");
//検索要素を指定
WebElement element = driver.findElement(By.id("gbqfq"));
//検索Keyを設定
element.sendKeys("apple 新製品");
//検索
element.submit();
//終了
driver.quit();
}
}