Кто-нибудь сталкивался с проблемой, когда веб-драйвер находит нужный элемент, вводит в него текст, а затем выдает исключение WebDriverTimeout, говоря, что для поиска того же элемента, в который он только что отправил текст, требуется слишком много времени?Если я оберну этот блок кода в try-catch, который перехватит исключение тайм-аута, тест будет успешно выполнен, но это не будет правильным способом сделать это.
Я использую c # seleniumи chromedriver 2.44
Обновление: Начальная конфигурация ожидания и само действие:
var driver = new ChromeDriver();
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(20);
driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(3);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(2);
...
var searchLocator = By.Id("searchByName");
driver.GetElement(searchLocator, 20, element => element.Displayed).SendKeys("test");
Расширение GetElement:
public static IWebElement GetElement(this IWebDriver driver, By locator, double timeout, Func<IWebElement, bool> condition)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout));
wait.IgnoreExceptionTypes(typeof(StaleElementReferenceException));
wait.Until(drv =>
{
var element = driver.FindElement(locator);
return condition(element);
});
return driver.FindElement(locator);
}
StackTrace:
Result StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebElement.Execute(String commandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebElement.SendKeys(String text)
at Tests.Steps.SearchSteps.WhenTheUserFillsTheSearchFieldWith(String searchFieldName, String data) in C:\...Tests\Steps\SearchSteps.cs:line 64
at lambda_method(Closure , IContextManager , String , String )
at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(IContextManager contextManager, StepInstance stepInstance)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep()
at TechTalk.SpecFlow.TestRunner.CollectScenarioErrors()
at Tests.Features.SearchFeature.ScenarioCleanup()
at Tests.Features.SearchFeature.CheckSearch() in C:\...Tests\Features\Search.feature:line 167
Result Message:
OpenQA.Selenium.WebDriverTimeoutException : timeout
(Session info: chrome=70.0.3538.110)
(Driver info: chromedriver=2.44.609538
(b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 6.3.9600 x86_64)