반응형

chromedriver 다운로드

Dependencies

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-chrome-driver</artifactId>
    <version>3.14.0</version>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.14.0</version>
</dependency>

Basic

ChromeOptions options = new ChromeOptions();

ChromeDriverService service = new ChromeDriverService.Builder()
    .usingDriverExecutable(new File("webdriver/chromedriver.exe"))
    .usingAnyFreePort()
    .build();

WebDriver driver = new ChromeDriver(service, options);
driver.get("https://google.com");

driver.quit();

Setting - headless

options.addArguments("headless");

Setting - proxy

<dependency>
    <groupId>net.lightbody.bmp</groupId>
    <artifactId>browsermob-core</artifactId>
    <version>2.1.5</version>
    <scope>compile</scope>
</dependency>
BrowserMobProxy proxy = new BrowserMobProxyServer();
proxy.setTrustAllServers(true);
proxy.enableHarCaptureTypes(SetUtils.union(CaptureType.getRequestCaptureTypes(), CaptureType.getResponseCaptureTypes()));
proxy.start();

options.setCapability(CapabilityType.PROXY, ClientUtil.createSeleniumProxy(proxy));
options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
options.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
options.addArguments("--ignore-certificate-errors");

// 사용 완료 후 종료해줘야 프로세스가 끝남
proxy.stop();

package capture

proxy.newHar("test");

driver.get("https://google.com");

for (HarEntry harEntry : proxy.getHar().getLog().getEntries()) {
    System.out.println(harEntry.getRequest().getUrl());
    System.out.println(harEntry.getResponse().getContent().getText());
}

element

driver.findElement(By.cssSelector("#loginId")).isDisplayed();
driver.findElement(By.cssSelector("#loginId")).sendKeys("testId");
driver.findElement(By.cssSelector(".btn_login")).click();
반응형

'Development > Java' 카테고리의 다른 글

[Java] Heap Dump  (0) 2020.12.28
[Java] 명령어  (0) 2020.12.28
[Java] Apache HttpClient  (0) 2020.12.28
[Java] JWT(Json Web Token)  (0) 2020.12.28
[Java] Markdown 파싱  (0) 2020.12.28

+ Recent posts