2012-10-19 8 views
7

"select"コントロールから値を選択するSelenium 2テスト(C#で書かれています)を使用しています。選択すると、サーバーへのポストバックが発生し、ページの状態が更新されます。したがって、私は手動待機(thread.sleep)を実行して、ページが変更されるのを待つ値を選択しています。 Thread.Sleepでうまく動作します。しかし、Thread.Sleepは、私は、コードのすべての私のThread.Sleepラインを取るように良い理由の数で使用する悪い考えでは、すべての私のテストケースがバラバラになると私はWebDriverWaitを試してみました、暗黙的および明示的にどれも機能していないと非常に不満であるWebDriverWaitまたはImplicitlyWaitまたはExplicitlyWaitは機能しません

以下、私が試してみましたサンプルコード....

がある// 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")); 
    }); 

答えて

0

ここ

new WebDriverWait(driver, 30).until(ExpectedConditions.presenseOfElementLocated(byLocator)); 
+0

はい私が試したが、うまくいきませんでした。 –

1

を使用しようとは私のためにどのような作品である - >

WebDriverWait wait = new WebDriverWait(browser, new TimeSpan(0, 0, 30)); 

element = wait.Until<IWebElement>((driver) => 
    { 
    return driver.FindElement(By.Name("name_of_element"))); 
    }); 

IDで行うこともできます - >

WebDriverWait wait = new WebDriverWait(browser, new TimeSpan(0, 0, 30)); 

element = wait.Until<IWebElement>((driver) => 
    { 
    return driver.FindElement(By.Id("id_of_element"))); 
    }); 

あなたのコードをもっと見ることなく、それがなぜ機能していないのかを判断するのは難しいでしょう。

+0

私はそれを貼り付けることができるようにもっとコードが何であるかを教えてください。 –

0

私はstackoverflowので解決策を見つける:)、これは動作します:

click on partialLinkText("Exit") 
remote.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS) 
remote.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS) 
// Thread.sleep(7000) // for js-work 
(new WebDriverWait(remote, 245)).until(presenceOfElementLocated(By.partialLinkText("""Entry for > technician"""))) 
// Thread.sleep(3000) // for js-works 
関連する問題