본문 바로가기
Selenium

[Selenium] 자바 | WebDriverWait.until()와 ExpectedConditions

by dev_haha 2023. 12. 6.

WebDriverWait

웹 드라이버에 대기시간을 주는 객체

Selenium의 실행속도는 웹페이지 로딩 속도보다 빠르다. 

때문에 element가 로딩될 때 까지 기다려야 하는 경우 사용한다.

예를 들어, 페이지 생성 버튼(더보기)을 누르기 위해 대기시간을 가져야 하는 경우

WebElement moreBtn = new WebDriverWait(driver, 10);

10초 대기 하겠다는 의미이다.

 

WebDriverWait.until()

명시적 대기(Explict wait)라고 한다.

moreBtn = new WebDriverWait(driver, 10)
		.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.cssSelector(css))));

css는 엘리먼트 경로

엘리먼트를 클릭할 수 있을 때까지 최대 10초간 대기하라는 코드이다. 

대기 조건에 사용되는 클래스가 ExpectedConditions이다.