셀레니움 자바코드 예제
요소 찾기
Variation |
Description |
Sample |
By.className |
"class"속성의 값을 기반으로 요소를 찾습니다. |
findElement(By.className("someClassName")) |
By.cssSelector |
드라이버의 기본 CSS 선택기 엔진을 기반으로 요소를 찾습니다. |
findElement(By.cssSelector("input#email")) |
By.id |
"id"속성 값으로 요소를 찾습니다. |
findElement(By.id("someId")) |
By.linkText |
표시되는 정확한 텍스트로 링크 요소를 찾습니다. |
findElement(By.linkText("REGISTRATION")) |
By.name |
"name"속성의 값으로 요소를 찾습니다 |
findElement(By.name("someName")) |
By.partialLinkText |
주어진 링크 텍스트를 포함하는 요소를 찾습니다 |
findElement(By.partialLinkText("REG")) |
By.tagName |
태그 이름으로 요소를 찾습니다. |
findElement(By.tagName("div")) |
By.xpath |
XPath를 통해 요소를 찾습니다 |
findElement(By.xpath("//html/body/div/table/tbody/tr/td[2]/table/ tbody/tr[4]/td/table/tbody/tr/td[2]/table/tbody/tr[2]/td[3]/ form/table/tbody/tr[5]")) |
Get 명령어
Get 명령은 페이지 / 요소에 대한 다양한 중요 정보를 가져옵니다. 다음은 숙지해야 할 중요한 "get"명령입니다.
get() |
|
getTitle() |
|
getPageSource() |
|
getCurrentUrl() |
|
getText() |
|
Navigate 명령어
이 명령을 사용하면 다른 웹 페이지를 새로 고침하고 앞뒤로 전환 할 수 있습니다.
navigate().to() |
|
navigate().refresh() |
|
navigate().back() |
|
navigate().forward() |
|
브라우저 창 닫기 및 종료
close() |
|
quit() |
|
Waits
There are two kinds of waits.
1. Implicit wait(암시 적 대기)-프로그램 전체에서 기본 대기 시간을 설정하는 데 사용됩니다
- Explicit wait(명시 적 대기)-특정 인스턴스에 대해서만 대기 시간을 설정하는 데 사용