【问题标题】:How to press 'Esc' key in Selenium WebDriver using C#如何使用 C# 在 Selenium WebDriver 中按“Esc”键
【发布时间】:2014-01-10 23:18:09
【问题描述】:

我有一种情况,我必须按“ESC”键来停止页面加载..

这绝对是必要的,否则页面会持续加载一分钟。

如何让 selenium webdriver 按下“Esc”键。这必须使用 C# 来完成。

另外,请提及必须导入的类

【问题讨论】:

    标签: c# automation selenium-webdriver keypress


    【解决方案1】:

    您可以使用 Actions 类将密钥直接发送到浏览器。请看以下代码的最后两行:

    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);
    

    希望对您有所帮助。

    【讨论】:

    • 这对我有用,方法是在 SendKeys 之后调用 Perform 方法,如下所示:action.SendKeys(OpenQA.Selenium.Keys.Escape).Perform();
    • 在Java中最后一行是action.sendKeys(Keys.ESCAPE);
    【解决方案2】:

    也许这个会有所帮助:

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

    【讨论】:

      猜你喜欢
      • 2018-02-16
      • 2015-09-02
      • 1970-01-01
      • 2015-06-28
      • 1970-01-01
      • 1970-01-01
      • 2020-10-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多