[英]C#: How to send key combination in selenium's Keyboard.SendKeys
I'm using Selenium 2 on Windows to automate firefox. 我在Windows上使用Selenium 2自动执行Firefox。 I tried to send 'Alt+Esc' to the browser to minimise it on start. 我试图将“ Alt + Esc”发送到浏览器以使其在启动时最小化。 However firefox keeps typing the '{%ESC}' in its address bar. 但是,firefox始终在其地址栏中键入“ {%ESC}”。 What should I do? 我该怎么办? thanks. 谢谢。
using (driver = new FirefoxDriver(firefoxProfile))
{
driver.Keyboard.SendKeys("{%ESC}");
}
I use this to open a new window (with the keyboard input) and it works just fine 我用它来打开一个新窗口(使用键盘输入),它工作得很好
IWebDriver driver = new FirefoxDriver();
Actions action = new Actions(driver);
action.SendKeys(OpenQA.Selenium.Keys.Control + "n").Build().Perform();
I prefer: 我更喜欢:
element.SendKeys(Keys.Control + "a");
Now you can focus on the element and not only on the webdriver 现在您可以专注于元素,而不仅仅是Webdriver
Sending regular key use SendKeys("ab12#$")
. 发送常规密钥使用SendKeys("ab12#$")
。
Sending a modifier key (Keys.Shift, Keys.Control, or Keys.Alt) use 发送修饰键(Keys.Shift,Keys.Control或Keys.Alt)使用
.[KeyUp\keyDown]([OpenQA.Selenium.Keys.Control\OpenQA.Selenium.Keys.Alt...])
And you can combine them as needed: 您可以根据需要将它们组合:
action.KeyDown(OpenQA.Selenium.Keys.Shift).SendKeys("ThisWillBePrintedCAPS").KeyUp(OpenQA.Selenium.Keys.Shift).SendKeys("ThisWillBePrintedRegular").Build().Perform();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.