문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
wiki:java:selenium [2020/11/11 21:41] hylee |
wiki:java:selenium [2023/01/13 18:44] (현재) |
||
---|---|---|---|
줄 29: | 줄 29: | ||
\\ | \\ | ||
===== Chrome Driver Download ===== | ===== Chrome Driver Download ===== | ||
+ | \\ | ||
+ | > 현재 크롬버전 확인 \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | 위 사진같이 클릭하면 아래와 같은 화면이 나옵니다 \\ | ||
+ | 크롬 버전을 확인하면 됩니다. \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | 확인 후 아래 페이지로 이동하여 같은 버전의 driver를 다운로드 받으면 됩니다. \\ | ||
+ | [[https:// | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | ===== maven ===== | ||
+ | <code java> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
- | {{:wiki:java:selenium:chrome.png?200|}} | + | ===== Selenium code ===== |
- | {{:wiki:java:selenium:chrome_driver_download.png?200|}} | + | ==== java ==== |
- | {{:wiki:java:selenium:chrome_version.png?200|}} | + | <code java> |
+ | |||
+ | |||
+ | |||
+ | package main; | ||
+ | |||
+ | import java.util.concurrent.TimeUnit; | ||
+ | |||
+ | import org.openqa.selenium.By; | ||
+ | import org.openqa.selenium.WebDriver; | ||
+ | import org.openqa.selenium.WebElement; | ||
+ | import org.openqa.selenium.chrome.ChromeDriver; | ||
+ | |||
+ | public class SeleniumTest | ||
+ | { | ||
+ | |||
+ | public static void main(String[] args) | ||
+ | { | ||
+ | // TODO Auto-generated method stub | ||
+ | chromTest(); | ||
+ | |||
+ | } | ||
+ | |||
+ | public static void chromTest() throws IllegalStateException | ||
+ | { | ||
+ | WebDriver driver = null; | ||
+ | try | ||
+ | { | ||
+ | // drvier 설정 - | ||
+ | System.setProperty(" | ||
+ | // Chrome 드라이버 인스턴스 설정 | ||
+ | driver = new ChromeDriver(); | ||
+ | |||
+ | // 접속하고 싶은 URL | ||
+ | // 아래 URL은 구글번역입니다. | ||
+ | driver.get( | ||
+ | " | ||
+ | // 대기 설정 | ||
+ | driver.manage().timeouts().implicitlyWait(2, | ||
+ | // xpath 패턴의 값 selector. | ||
+ | WebElement element; | ||
+ | |||
+ | // test를 위한 배열 | ||
+ | String[] s_array = new String[3]; | ||
+ | s_array[0] = "This book aims to strengthen an understanding of the sculptural possibilities of form and space through developing a visual language and structure that recognizes and "; | ||
+ | s_array[1] = "gives priority to 3dimensional visual perception It is written so as to apply to both the active process of shaping 3D form and space and analyzing any existing visual situation Introduction"; | ||
+ | s_array[2] = " | ||
+ | |||
+ | // *[@id=" | ||
+ | |||
+ | // 배열 반복문 | ||
+ | for (String str : s_array) | ||
+ | { | ||
+ | // 언어선택하는 버튼 | ||
+ | element = driver.findElement(By.xpath("// | ||
+ | // 언어선택하는 버튼 클릭 | ||
+ | element.click(); | ||
+ | |||
+ | Thread.sleep(1000); | ||
+ | |||
+ | // 언어감지 버튼 선택 | ||
+ | element = driver.findElement(By.xpath( | ||
+ | "// | ||
+ | // 언어감지 버튼 클릭 | ||
+ | element.click(); | ||
+ | // 번역 할 input창 선택 | ||
+ | element = driver.findElement(By.xpath("// | ||
+ | // 번역 할 input창에 문장 넣기 | ||
+ | element.sendKeys(str); | ||
+ | // 대기 설정 | ||
+ | Thread.sleep(1000); | ||
+ | // css 패턴의 값 selector. | ||
+ | WebElement elementd = driver.findElement(By.cssSelector("# | ||
+ | |||
+ | System.out.println(" | ||
+ | // element 초기화 | ||
+ | element.clear(); | ||
+ | } | ||
+ | |||
+ | } catch (Throwable e) | ||
+ | { | ||
+ | e.printStackTrace(); | ||
+ | } finally | ||
+ | { | ||
+ | driver.close(); | ||
+ | |||
+ | // test 용 | ||
+ | System.exit(0); | ||
+ | } | ||
+ | |||
+ | // | ||
+ | |||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | ==== consol ==== | ||
+ | elementd | ||
+ | elementd | ||
+ | elementd | ||
+ | \\ | ||
+ | \\ | ||
+ | |||
+ | |||
+ | ===== CentOS에 크롬설치 ===== | ||
+ | '' | ||
+ | 크롬드라이버도 리눅스 버전을 받아야 합니다. \\ | ||
+ | \\ | ||
+ | 1. 크롬 repo 등록 \\ | ||
+ | <code bash> | ||
+ | $ vi / | ||
+ | </ | ||
+ | |||
+ | [google-chrome] | ||
+ | name=google-chrome | ||
+ | baseurl=http:// | ||
+ | enabled=1 | ||
+ | gpgcheck=1 | ||
+ | gpgkey=https:// | ||
+ | |||
+ | |||
+ | 2. 크롬 설치 \\ | ||
+ | <code bash> | ||
+ | $ yum install google-chrome-stable | ||
+ | </ | ||
+ | \\ | ||
+ | 3. 크롬 버전 확인 \\ | ||
+ | <code bash> | ||
+ | $ google-chrome --version | ||
+ | </ | ||
+ | \\ | ||
+ | |||
+ | ===== Tip ===== | ||
+ | 자바코드를 실행하면 크롬창이 뜨면서 번역하는 과정이 보여집니다. | ||
===== Troubleshooting ===== | ===== Troubleshooting ===== | ||
줄 41: | 줄 200: | ||
- | {{tag> | + | {{tag>도봉산핵주먹 java selenium}} |