2014-02-25 4 views
2

나는 다음과 같은 코드 from here (C# 버전)을 사용하고 있습니다 :셀레늄 명시 적 대기 설정 사용자 정의 호출 간격?

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); 
IWebElement myDynamicElement = wait.Until<IWebElement>((d) => 
    { 
     return d.FindElement(By.Id("someDynamicElement")); 
    }); 

을 그 조각 아래 문서는 말한다 : 성공적으로 반환 될 때까지 기본적으로

WebDriverWait가 ExpectedCondition마다 500 밀리 초를 호출합니다.

어떻게 여기에 다른 대기 시간 (예 : 10 밀리 초)이 포함되도록 코드를 수정할 수 있습니까?

답변

3

DefaultWait에는 폴링 간격이 있습니다.

DefaultWait<IWebDriver> wait = new DefaultWait(driver); 
wait.PollingInterval = TimeSpan.FromMilliseconds(10); 
+0

원래 샘플에 표시된대로 FindElement (By.Id ("someDynamicElement")); 부분을 포함시킬 수 있습니까? 아마도 잘못된 것이지만, 코드에서 1 행으로 코드를 대체 할 때 'OpenQA.Selenium.Support.UI.DefaultWait '형식의 인수가 필요합니다. '오류가 발생합니다. 나는 여러 가지 일을 시도했지만, 아직 그것을 고칠 수있는 방법을 충분히 알지 못했습니다. – Keavon

+0

@Kavon, [MatthewThomasGB] (https://stackoverflow.com/users/4638372/matthewthomasgb)의 답변을 아래에서 시도해 보셨습니까? 'WebDriverWait' 클래스가 제네릭 타입 –

+0

@ dey.shin을 사용하지 않기 때문에 주어진 대답은 오류를 제거해야합니다.이 프로젝트는 오래전부터 끝났기 때문에 이것을 시도하지 않았습니다. – Keavon

3

당신은 WebDriverWait의 특정 인스턴스에 대한 폴링 간격을 설정할 수 있습니다, 아래의 코드는 요소를 찾습니다 20 초 후에 모든 200 밀리 초를 폴링합니다.

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20)); 

wait.PollingInterval = TimeSpan.FromMilliseconds(200); 

IWebElement myDynamicElement = wait.Until<IWebElement>((d) => 
{ 
return d.FindElement(By.Id("someDynamicElement")); 
}); 
관련 문제