C#:如何发送硒键组合';s Keyboard.SendKeys

本文关键字:Keyboard SendKeys 组合 何发送 | 更新日期: 2023-09-27 18:30:00

我在Windows上使用Selenium 2来自动化firefox。我尝试将"Alt+Esc"发送到浏览器,以在启动时将其最小化。但是firefox一直在其地址栏中键入"{%ESC}"。我该怎么办?谢谢

using (driver = new FirefoxDriver(firefoxProfile))
{
    driver.Keyboard.SendKeys("{%ESC}");
}

C#:如何发送硒键组合';s Keyboard.SendKeys

我用它来打开一个新窗口(使用键盘输入),它运行得很好

IWebDriver driver = new FirefoxDriver();                          
Actions action = new Actions(driver);
action.SendKeys(OpenQA.Selenium.Keys.Control + "n").Build().Perform();

我更喜欢:

element.SendKeys(Keys.Control + "a");

现在您可以专注于元素,而不仅仅是Web驱动程序

使用SendKeys("ab12#$")发送常规密钥
使用发送修改键(Keys.Shift、Keys.Control或Keys.Alt)

.[KeyUp'keyDown]([OpenQA.Selenium.Keys.Control'OpenQA.Selenium.Keys.Alt...])

您可以根据需要组合它们:

action.KeyDown(OpenQA.Selenium.Keys.Shift).SendKeys("ThisWillBePrintedCAPS").KeyUp(OpenQA.Selenium.Keys.Shift).SendKeys("ThisWillBePrintedRegular").Build().Perform();