static void Main(string[] args) { IWebDriver driver = new EdgeDriver(IE_DRIVER_PATH); driver.Navigate().GoToUrl("http://www.bing.com"); IWebElement searchInput = driver.FindElement(By.Id("sb_form_q")); searchInput.SendKeys("Hello World!"); searchInput.SendKeys(Keys.Enter); driver.Close(); }
static void Main(string[] args) { RemoteWebDriver driver = null; string serverPath = "Microsoft Web Driver"; try { if (System.Environment.Is64BitOperatingSystem) { serverPath = Path.Combine(System.Environment.ExpandEnvironmentVariables("%ProgramFiles(x86)%"), serverPath); } else { serverPath = Path.Combine(System.Environment.ExpandEnvironmentVariables("%ProgramFiles%"), serverPath); } // location for MicrosoftWebDriver.exe EdgeOptions options = new EdgeOptions(); options.PageLoadStrategy = EdgePageLoadStrategy.Eager; driver = new EdgeDriver(serverPath, options); //Set page load timeout to 5 seconds driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(5)); // Navigate to https://www.bing.com/ driver.Url = "https://www.bing.com/"; //// Find the search box and query for webdriver RemoteWebElement element = (RemoteWebElement)driver.FindElementById("sb_form_q"); element.SendKeys("webdriver"); element.SendKeys(Keys.Enter); // Wait for search result WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5)); wait.Until(x => x.Title.Contains("webdriver")); Screenshot shot = driver.GetScreenshot(); shot.SaveAsFile("output.png", ImageFormat.Png); } catch (Exception e) { Console.WriteLine(e.Message); } finally { if (driver != null) { driver.Close(); } } }