簡體   English   中英

在使用顯式等待之前關閉隱式等待,因為顯式等待需要隱式等待的時間

[英]Turning Off Implicit Wait before using explicit wait as explicit wait takes time from Implicit wait

場景:我在每次操作(單擊/發送鍵)后尋找錯誤元素。

由於應用程序中的不一致,我同時使用隱式和顯式等待。 初始化驅動程序時,隱式等待設置為 10 秒。 每次點擊后調用下面的代碼來檢查頁面中的任何錯誤元素,如果我不關閉隱式等待(通過設置為 0),顯式等待仍然需要 10 秒等待(在隱式等待中給出)盡管指定等待 Object 中的 1 秒時間用於顯式等待。

問題:是否可以關閉隱式等待並在所需檢查后重新設置以查找錯誤元素

try {
    Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(0);

    var wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(1));
    isDisp = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(errorLocator));
    Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

    Log.setTestDebug("Checking error after");
}

最佳做法是不使用隱式等待,我同意@pcalkins 的觀點。

但是正如您在問題的第一部分提到的那樣,由於不一致,如果您被迫使用隱式等待,則關閉並打開它們是安全的。 我用我個人的經歷來回答這個問題。 我並不是說這是最好的方法或做法。

如果您打算這樣做,我建議您在 finally 塊中重新打開隱式等待。

try
{
  turn off implicit wait
  do error check
}
catch 
{
  exception handling
}
finally
{
  turn on implicit wait
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM