У меня есть программа на VS, использующая C # с Selenium, которая вводит данные в текстовое поле определенного веб-сайта.И я нашел этот метод онлайн, который ждет, пока элемент не существует.
Попытка вызова метода WaitUntilElementExists из другого класса, но он не работает.Не знаю, пропустил ли я что-то.Ценю, если вы могли бы помочь мне.Заранее спасибо!
public static void InputTextbox(IWebDriver wDriver, string sElement, string sValue, int iIndex)
{
//calling WaitUntilElementExists method
var wait = new WebDriverWait(wDriver, TimeSpan.FromSeconds(20));
wait.Until(ExpectedConditions.ElementExists(By.Name("value")));
//input text box
}
public static class WaitForElement
{
public static IWebElement WaitUntilElementExists(this IWebDriver wDriver, By elementLocator, int iTimeout)
{
try
{
if (iTimeout > 0)
{
var wait = new WebDriverWait(wDriver, TimeSpan.FromSeconds(iTimeout));
return wait.Until(ExpectedConditions.ElementExists(elementLocator));
}
return wDriver.FindElement(elementLocator);
}
catch (NoSuchElementException)
{
Console.WriteLine("Element with locator: '" + elementLocator + "' was not found in current context page.");
throw;
}
}
}