简体   繁体   中英

How to press 'Esc' key in Selenium WebDriver using C#

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

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.

也许这个会有所帮助:

 System.Windows.Forms.SendKeys.SendWait("{ESC}");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM