2016-03-22 9 views
0

driver.wait or driver.sleepコマンドの使用を避ける方法はありますか?セレンで待ち時間とスリープを避ける方法はありますか?

driver.manage().timeouts().implicitlyWait(3000)のようなものが、要素が配置されるまで一般的なタイムアウトとして使用されますか?

私は、自動テストで新しいですし、あなたがセットアップすることができ、明示的および暗黙の待機をセレンに:)

+0

私の回答は役に立ちましたか? –

+1

私は一般的な仕様で使用されるように、蛇送り方式で "迂回路"を作りましたが、あなたの答えは間違いなく助けてくれました、ありがとうございます。 – MirceaM

答えて

2

をコーディングします。

明示待ちの例、すなわち表示される特定の要素に対して明示的に待機(すなわち、時間の任意の量を待つ)

IWebDriver driver = new FirefoxDriver(); 
driver.Url = "http://somedomain/url_that_delays_loading"; 
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); 
IWebElement myDynamicElement = wait.Until<IWebElement>((d) => 
{ 
    return d.FindElement(By.Id("someDynamicElement")); 
}); 

暗黙ウェイトの例である:

WebDriver driver = new FirefoxDriver(); 
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); 
driver.Url = "http://somedomain/url_that_delays_loading"; 
IWebElement myDynamicElement = driver.FindElement(By.Id("someDynamicElement")); 

詳細については、hereを参照してください。

0

あなたは要素の分の明示的な待ち時間

new WebDriverWait(driver, new TimeSpan(0, 1, 0)).Until(ExpectedConditions.ElementIsVisible(By locator)); 

待機を使用することができます。

0

ありがとうございました。私は、次のと「回り道」を作るために管理:

function findClickElem(locator, path, timeout) { 

      driver.wait(generalspecs.getSpecs().until.elementLocated(generalspecs.getSpecs().By[locator](path)), timeout).then(function(elem){ 
       if(elem){ 
        elem.click(); 
       }else{ 
        console.log('no element!'); 
       } 
      }); 
     } 

ただgeneralspecsに加えて、私は待機を使用して、要素をクリックするたびに呼び出されます。

findClickElem("xpath" ,"//li[contains(@class, 'classCustom1')]", 15000); 
関連する問題