「選択」コントロールから値を選択する Selenium 2 テスト (C# で記述) を使用しています。選択すると、サーバーへのポストバックが発生し、ページの状態が更新されます。したがってthread.sleep
、ページが変更されるまで待機する値を選択した後、手動待機 ( ) を実行しています。Thread.Sleep で問題なく動作します。ただし、Thread.Sleep
多くの正当な理由で使用するのは悪い考えであるため、すべてのコード行を取り出すとThread.Sleep
、すべてのテストケースがバラバラになり、WebDriverWait を試してみましたが、暗黙的および明示的に何も機能せず、非常に不満がありました
以下は私が試したサンプルコードです....
//WebDriverWait
public IWebElement WaitForElement(By by)
{
// Tell webdriver to wait
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
wait.PollingInterval = TimeSpan.FromSeconds(2);
wait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(NoSuchFrameException));
wait.IgnoreExceptionTypes(typeof(StaleElementReferenceException), typeof(StaleElementReferenceException));
IWebElement myWait = wait.Until(x => x.FindElement(by));
return myWait;
}
これも試してみました:
WebDriverWait wait = new WebDriverWait(new SystemClock(), driver, TimeSpan.FromSeconds(30), TimeSpan.FromMilliseconds(100));
//暗黙的に:
driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));
//明示的な待機:
IWebDriver driver = new FirefoxDriver();
driver.Url = "http://somedomain/url_that_delays_loading";
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
IWebElement myDynamicElement = wait.Until<IWebElement>((d) =>
{
return d.FindElement(By.Id("someDynamicElement"));
});