2014-09-02 2 views
0

fluentWait 클래스의 timeoutException 방법을 사용하려고 시도하는 동안,FluentWait의 timeoutException 메서드를 사용하는 방법?

FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver); 
wait.timeoutException("test timeoutException",new MyException("hello")); 

얻기 그

The method timeoutException(String, Throwable) from the type FluentWait<WebDriver> is not visible 

왜 이렇게 경고? 이 방법을 사용하는 방법?

답변

0

timeoutException 방법을 재정의함으로써, 우리는 대기 시간 초과 다른 예외를 트리거 할 수 있습니다. timeoutException 메서드를 덮어 쓰는 다음 코드를 고려하십시오. 타임 아웃이 발생하면

FluentWait<WebDriver> wait=new FluentWait<WebDriver>(driver){ 
    @Override 
    protected RuntimeException timeoutException(String Message,Throwable lastException)  
    { 
     throw new MyException("A New Exception instead of TimeOutException"); 
    } 
}; 
wait.ignoring(NoSuchElementException.class) 
    .withTimeout(2, TimeUnit.SECONDS); 

WebElement foo = wait.until(new Function<WebDriver, WebElement>() { 
    public WebElement apply(WebDriver driver) { 
    return driver.findElement(By.id("foo")); 
    } 
}); 

은 그래서, 대신 TimeoutException의, 사용자 정의 예외는 ERKI을

com.example.tests.MyException: A New Exception instead of TimeOutException 
at com.example.tests.sampleTest$1.timeoutException(sampleTest.java:40) 
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:228) 
at com.example.tests.sampleTest.test(sampleTest.java:45) 
0

FluentWait을 보면 timeoutExcpetion에 액세스가 보호되어있어 이와 같이 사용할 수 없음을 알게 될 것입니다.

나는 당신이 달성 하려는지 잘 모르겠지만, 당신은 일반적으로 좋아 사용하면

FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver); 
wait.withTimeout(10, TimeUnit.SECONDS) 
     .ignoring(NoSuchElementException.class) 
     .pollingEvery(1, TimeUnit.SECONDS) 
     .withMessage("Trololo") 
     .until(ExpectedConditions.invisibilityOfElementLocated(By.id("id"))); 
+0

감사를 던져, 그러나 이것은 내가, 내가 셀레늄을 공부하고 무엇을 찾고 있었다하지 않고 방법을 이해할 수있을 것이다 timeoutException을 제외한 FluentWait의 다른 메소드를 사용하십시오. 보호 된 방법에 대한 힌트에주의를 기울임으로써 그 사용법을 알아 내고 대답으로 업데이트 할 수있었습니다. – Kavan

관련 문제