어떻게 구현해야하는지에 대한 예를 들어 보겠습니다.
기본 시간으로 time 매개 변수를 사용하여 기본 waitUntil 메소드를 작성합니다.
private void waitUntil(ExpectedCondition<WebElement> condition, Integer timeout) {
timeout = timeout != null ? timeout : 5;
WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.until(condition);
}
그러면 도우미 메서드를 사용하여 표시 대기 시간을 만들거나 클릭 대기 시간을 설정할 수 있습니다.
public Boolean waitForIsDisplayed(By locator, Integer... timeout) {
try {
waitUntil(ExpectedConditions.visibilityOfElementLocated(locator),
(timeout.length > 0 ? timeout[0] : null));
} catch (org.openqa.selenium.TimeoutException exception) {
return false;
}
return true;
}
elementToBeClickable과 비슷한 기능을 수행 할 수 있습니다.
public Boolean waitForIsClickable(By locator, Integer... timeout) {
try {
waitUntil(ExpectedConditions.elementToBeClickable(locator),
(timeout.length > 0 ? timeout[0] : null));
} catch (org.openqa.selenium.TimeoutException exception) {
return false;
}
return true;
}
그래서 우리는 이것을 사용하기 위해 클릭 할 수있는 클릭 방법을 만들 수 있습니다
public void click(By locator) {
waitForIsClickable(locator);
driver.findElement(locator).click();
}
내가 더 적은을 만들기 위해 내 주장에 사람들을 다시 사용할 수 있기 때문에 waitForIsDisplayed 및 waitForIsClickable가 만드는 이유 다루기 힘든. 또한
assertTrue("Expected something to be found, but that something did not appear",
waitForIsDisplayed(locator));
, 당신은 방법 (오초)에 지정된 기본 시간 대기 방법을 사용하거나 수행 할 수 있습니다
waitForIsDisplayed(locator, 20);
을 던지기 전에 20 초 최대를 기다릴 것
예외.
문제는 단추가 표시되고 클릭 가능하므로 예외가 발생하지 않습니다. 이 문제를 볼 때 Selenium이 클릭 할 때 버튼에 기능이 없거나 Selenium의 클릭이 둔합니다. 나는 이것을 이해하려고 노력하고있다. Selenium 2.x에 돌아 왔고 정상적으로 작동합니다. –
아직 디버깅을 시도하지 않았 으면합니다.또한 사용중인 로케이터를 확인하십시오. 클릭하려고 시도한 부모 또는 자녀를 사용하십시오. 나는 셀레늄 3에 대한 클릭 메쏘드에 대한 어떤 변화도 모르고있다. – Cromzinc