我正在阅读SeleniumHQ文档并遇到以下声明.
"警告:不要混合隐式和显式等待.这样做可能会导致不可预测的等待时间.例如,设置10秒的隐式等待和15秒的显式等待可能会导致20秒后发生超时."
出于某种原因,我无法理解这一点.总超时20秒是我的主要困惑点.任何人都可以解释我是否遗漏了什么?
编辑
我的问题不是关于混合这些等待的实施/后果.它完全是关于doc上的语句和超时计算.
第二次编辑
根据下面的测试,看起来文档是正确的.我仍然需要解释.
using System;
using System.Diagnostics;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace Test
{
[TestFixture]
public class Test
{
private IWebDriver _webDriver;
[Test]
public void ExplicitVsImplicitWaitTest()
{
_webDriver = new ChromeDriver();
_webDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
_webDriver.Navigate().GoToUrl("https://www.google.com/");
_webDriver.Manage().Window.Maximize();
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
try
{
//new WebDriverWait(_webDriver, TimeSpan.FromSeconds(15)).Until(
//ExpectedConditions.ElementExists(By.CssSelector("Should Fail")));
_webDriver.FindElement(By.CssSelector("Should Fail"));
}
catch ( NoSuchElementException exception)
//catch ( OpenQA.Selenium.WebDriverTimeoutException)
{
stopwatch.Stop();
Console.WriteLine(stopwatch.Elapsed);
}
_webDriver.Quit();
}
}
}
Run Code Online (Sandbox Code Playgroud)
时间秒:00:00:10.0167290
using System; …Run Code Online (Sandbox Code Playgroud)