Reputation: 601
I have a situation where I have to press on the 'ESC' key to stop the page from loading..
This is definitely needed as otherwise the page will keep on loading for a minute.
How do I make selenium webdriver to press the 'Esc' key. This has to be done using C#.
Also, kindly mention the class that has to be imported
Upvotes: 17
Views: 27369
Reputation: 274
Maybe this one will help:
System.Windows.Forms.SendKeys.SendWait("{ESC}");
Upvotes: 1
Reputation: 6950
You can send keys directly to the browser using Actions class. See last two lines of the following code:
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Interactions;
IWebDriver driver = new FirefoxDriver(ffprofile);
driver.Navigate().GoToUrl("http://www.google.com");
driver.FindElement(By.Name("q")).SendKeys("Stack Overflow");
driver.FindElement(By.Name("q")).Submit();
Actions action = new Actions(driver);
action.SendKeys(OpenQA.Selenium.Keys.Escape);
Hope that helps.
Upvotes: 20