2017-12-22 13 views
-2

Selenium에서 ExplicitWait을 사용할 때 WebDriverTimeoutException을 무시하려고합니다.VB.Net Selenium WebDriverWait.IgnoreExceptionTypes WebDriverTimeoutException을 표시하지 않음

Dim wait As New WebDriverWait(driver, New TimeSpan(0, 0, 10)) 
wait.IgnoreExceptionTypes(GetType(WebDriverTimeoutException)) 
wait.Until(ExpectedConditions.InvisibilityOfElementLocated(By.Id("foo"))) 

NoSuchElementException과 같이 다른 셀렌 예외의 경우에도 정상적으로 작동합니다. 그러나 WebDriverTimeoutExceptions를 사용하면 무시할 수 없습니다.

나는 Try Catch 블록을 사용할 수 있다는 것을 알고 있지만, 이것이 의도 한대로 작동하지 않는 이유가 궁금하다.

Dim wait As New WebDriverWait(driver, New TimeSpan(0, 0, 10)) 
wait.IgnoreExceptionTypes(GetType(WebDriverTimeoutException)) 
wait.Until(ExpectedConditions.InvisibilityOfElementLocated(By.Id("foo"))) 

당신이 효과적으로 element이 요소가 HTML DOM에 제시해야 의미 InvisibilityOfElementLocated로 설정 ExpectedConditionsWebDriverWait 유도 : 코드 당으로

+0

원하는 요소가 지정한 10 개 내에 없으면 어떻게해야합니까? 타임 아웃 예외가 발생했습니다. 의도적 인거야. – JeffC

답변

0

아래의 몇 가지 근본적인 문제가 있습니다 당신은 그것이 보이지 않을 때까지 기다리고 싶습니다. InvisibilityOfElementLocated 내부 NoSuchElementExceptionStaleElementReferenceException하지만 WebDriverTimeoutExceptions을 처리하는 것을 의미

try: 
    return _element_if_visible(_find_element(driver, self.locator), False) 
except (NoSuchElementException, StaleElementReferenceException): 
    # In the case of NoSuchElement, returns true because the element is 
    # not present in DOM. The try block checks if the element is present 
    # but is invisible. 
    # In the case of StaleElementReference, returns true because stale 
    # element reference implies that element is no longer visible. 
    return True 

: 당신이 소스 코드를 볼 경우는 다음과 같이 정의된다 InvisibilityOfElementLocated의 (나는 Python 보았다). WebDriverWait 인스턴스를 초기화하는 당신은, 그래서 근본적으로 IgnoreExceptionTypes 반면에 WebDriverTimeoutException를 추가하는 결과를 WebDriverTimeoutExceptions

를 볼 보이지 않게했다 element의 부재에 존재 중단하면서 timespan 후에는 언급 ExpectedConditions.InvisibilityOfElementLocated()nil이다.