Код: Выделить всё
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Support.UI;
using SeleniumExtras.WaitHelpers;
private string GetFormData(string url, string textToSend)
{
string result;
IWebDriver driver = null;
try
{
string browserName = GetDefaultBrowserName();
switch (browserName)
{
case "MSEdge":
driver = new EdgeDriver();
break;
case "Chrome":
driver = new ChromeDriver();
break;
case "Firefox":
driver = new FirefoxDriver();
break;
default:
return string.Empty;
}
driver.Navigate().GoToUrl(url);
IWebElement textField = driver.FindElement(By.Id("textinput"));
textField.SendKeys(textToSend);
driver.FindElement(By.XPath("//input[@type='button' and @value='nameOfButton']")).Click();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30))
{
PollingInterval = TimeSpan.FromMilliseconds(200)
};
wait.Until(ExpectedConditions.TextToBePresentInElementValue(By.Id("output"), "finished"));
IWebElement Field = driver.FindElement(By.Id("output"));
result = Field.GetAttribute("value");
}
catch (Exception ex)
{
_ = MessageBox.Show($"An unexpected error occurred. {ex.Message}", $"Title", MessageBoxButton.OK, MessageBoxImage.Exclamation);
result = string.Empty;
}
finally
{
if (driver != null)
{
((IDisposable)driver).Dispose();
}
}
return result;
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... se-version