ChromOptions를 설정하고 난 후 아주 잘 된다링.
소스코드 기록
com.first.mavenapp.SeleniumSample.java
package com.first.mavenapp;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class SeleniumSample {
private static final String WEB_DRIVER_ID = "webdriver.chrome.driver";
// /usr/bin/chromedriver
private static final String WEB_DRIVER_PATH = "/usr/bin/chromedriver";
public static void main(String[] args) {
System.setProperty(WEB_DRIVER_ID, WEB_DRIVER_PATH);
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
WebDriver driver = new ChromeDriver(options);
try {
driver.get("https://www.google.com");
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("Selenium");
searchBox.submit();
System.out.println("Page title is : " + driver.getTitle());
} catch (Exception e) {
e.printStackTrace();
} finally {
driver.quit();
}
}
}
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.first.mavenapp</groupId>
<artifactId>realMaven</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>realMaven</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/versions/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-api -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.141.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-remote-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.141.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.141.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>3.141.0</version>
</dependency>
</dependencies>
</project>
명령어 정리
// pom.xml, target 있는 경로
gkrud@DESKTOP-HJPVGM2:~/mavenTestProject/realMaven$ mvn clean install
// jar파일 있는 경로
gkrud@DESKTOP-HJPVGM2:~/mavenTestProject/realMaven/target$ java -cp realMaven-1.0-SNAPSHOT.jar com.first.mavenapp.SeleniumSample
'Linux' 카테고리의 다른 글
[Ubuntu/Java] Chrome/Selenium 터미널(쉘) 실행 성공한 썰.txt (0) | 2024.01.19 |
---|---|
[Linux/Ubuntu] maven pom.xml 수정 | Maven build plugin 설정 | 크롬&크롬드라이버 버전 맞추기 | (0) | 2024.01.19 |
[Linux/Ubuntu] 우분투에서 Maven 설치 및 프로젝트 생성 (VSCode) (0) | 2024.01.17 |
[Linux/Ubuntu] 우분투에 Maven 설치 및 프로젝트 생성하기 (0) | 2024.01.16 |
[Ubuntu] 우분투 자바 크롬/크롬드라이버/셀레니움 설치 (0) | 2024.01.12 |