사용자 도구

사이트 도구


wiki:java:selenium

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
wiki:java:selenium [2020/11/11 22:02]
hylee
wiki:java:selenium [2023/01/13 18:44] (현재)
줄 52: 줄 52:
 </code> </code>
  
-===== Selenium java code =====+===== Selenium code ===== 
 +==== java ====
 <code java> <code java>
 +
 +
 +
 package main; package main;
  
줄 82: 줄 86:
  // Chrome 드라이버 인스턴스 설정  // Chrome 드라이버 인스턴스 설정
  driver = new ChromeDriver();  driver = new ChromeDriver();
- // 스크립트를 사용하기 위한 캐스팅 
-// JavascriptExecutor js = (JavascriptExecutor) driver; 
- 
- // element 에 버튼을 찾아서 넣어주고 아래와 같이 작성하면 
- // 해당 버튼을 클릭합니다. 
-// js.executeScript("arguments[0].click();", element); 
  
  // 접속하고 싶은 URL  // 접속하고 싶은 URL
줄 96: 줄 94:
  driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);  driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
  // xpath 패턴의 값 selector.  // xpath 패턴의 값 selector.
- WebElement element = driver.findElement(By.xpath("//*[@id='tw-source-text-ta']"));+ WebElement element;
  
  // test를 위한 배열  // test를 위한 배열
- String[] s_array = new String[2];+ 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[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[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="tw-sl"]/span[1]
  
- for (String aa : s_array)+ // 배열 반복문 
 + for (String str : s_array)
  {  {
 + // 언어선택하는 버튼
 + element = driver.findElement(By.xpath("//*[@id='tw-sl']/span[1]"));
 + // 언어선택하는 버튼 클릭
 + element.click();
  
- element.sendKeys(aa);+ Thread.sleep(1000);
  
 + // 언어감지 버튼 선택
 + element = driver.findElement(By.xpath(
 + "//*[@id='tw-container']/g-expandable-container/div/div/div[6]/g-expandable-container/div/g-expandable-content/span/div/div[3]/div[1]/div/div[1]/div[2]"));
 + // 언어감지 버튼 클릭
 + element.click();
 + // 번역 할 input창 선택
 + element = driver.findElement(By.xpath("//*[@id='tw-source-text-ta']"));
 + // 번역 할 input창에 문장 넣기
 + element.sendKeys(str);
  // 대기 설정  // 대기 설정
  Thread.sleep(1000);  Thread.sleep(1000);
- 
  // css 패턴의 값 selector.  // css 패턴의 값 selector.
  WebElement elementd = driver.findElement(By.cssSelector("#tw-target-text > span"));  WebElement elementd = driver.findElement(By.cssSelector("#tw-target-text > span"));
  
  System.out.println("elementd : " + elementd.getText());  System.out.println("elementd : " + elementd.getText());
- 
  // element 초기화  // element 초기화
  element.clear();  element.clear();
줄 138: 줄 149:
  
 } }
 +
  
  
줄 143: 줄 155:
  
  
-===== consol ===== +==== consol ==== 
-  elementd : 이 책은 인식하고 인식하는 시각적 언어와 구조를 개발하여 형태와 공간의 조각 적 가능성에 대한 이해를 강화하는 것을 목표로합니다. \\+  elementd : 이 책은 인식하고 인식하는 시각적 언어와 구조를 개발하여 형태와 공간의 조각 적 가능성에 대한 이해를 강화하는 것을 목표로합니다.
   elementd : 3 차원 시각 인식을 우선시하며 3 차원 형태와 공간을 형성하는 능동적 인 과정과 기존의 시각 상황을 분석하는 과정 모두에 적용 할 수 있도록 작성되었습니다.   elementd : 3 차원 시각 인식을 우선시하며 3 차원 형태와 공간을 형성하는 능동적 인 과정과 기존의 시각 상황을 분석하는 과정 모두에 적용 할 수 있도록 작성되었습니다.
 +  elementd : 단어, 구, 구에 사용할 수있는 유료 서비스
 +  \\
 +  \\
 +  
 +  
 +===== CentOS에 크롬설치 =====
 +''서버환경에 크롬을 설치해야  Selenium이 동작합니다.'' \\
 +크롬드라이버도 리눅스 버전을 받아야 합니다. \\
 +\\
 +1. 크롬 repo 등록 \\
 +<code bash>
 +$ vi /etc/yum.repos.d/google-chrome.repo
 +</code>
 +
 +  [google-chrome] 
 +  name=google-chrome 
 +  baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch 
 +  enabled=1 
 +  gpgcheck=1 
 +  gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub 
 +
 +
 +2. 크롬 설치 \\
 +<code bash>
 +$ yum install google-chrome-stable 
 +</code>
 + \\
 +3. 크롬 버전 확인 \\
 +<code bash>
 +$ google-chrome --version 
 +</code>
 +\\
 +  
 ===== Tip ===== ===== Tip =====
 자바코드를 실행하면 크롬창이 뜨면서 번역하는 과정이 보여집니다. 자바코드를 실행하면 크롬창이 뜨면서 번역하는 과정이 보여집니다.
/volume1/web/dokuwiki/data/attic/wiki/java/selenium.1605099771.txt.gz · 마지막으로 수정됨: 2022/03/10 19:52 (바깥 편집)