//Thread.Sleep(3000);
IWebElement? existedRegistry = driver.FindElements(By.XPath("//td[text()='" + currentRegistryNumber + "']")).FirstOrDefault();
if (existedRegistry != null)
{
existedRegistry.Click();
return;
}
using IWebElements = System.Collections.ObjectModel.ReadOnlyCollection<OpenQA.Selenium.IWebElement>;
public static class WebDriverExtensions
{
public static IWebElement FindElement(this IWebDriver driver, By by, double timeoutInSeconds)
{
if (timeoutInSeconds > 0)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
return wait.Until<IWebElement>(drv => {
try
{
return drv.FindElement(by);
}
catch
{
return null;
}
});
}
return driver.FindElement(by);
}
// Похоже это работает не так, как мне бы хотелось
public static IWebElements FindElements(this IWebDriver driver, By by, double timeoutInSeconds)
{
if (timeoutInSeconds > 0)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
return wait.Until<IWebElements>(drv => {
try
{
return drv.FindElements(by);
}
catch
{
return null;
}
});
}
return driver.FindElements(by);
}
}
private void ClickOnElement(By by, double timeoutInSeconds)
{
IWebElement? element = driver.FindElement(by, timeoutInSeconds);
if (element != null)
{
var fluentWait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
fluentWait.Until(webDriver =>
{
try
{
element.Click();
}
catch (Exception ex)
{
if (ex is StaleElementReferenceException ||
ex is StaleElementReferenceException ||
ex is ElementClickInterceptedException)
{
return false;
}
else
{
throw;
}
}
return true;
});
}
}