簡體   English   中英

C#:如何在Selenium的Keyboard.SendKeys中發送組合鍵

[英]C#: How to send key combination in selenium's Keyboard.SendKeys

我在Windows上使用Selenium 2自動執行Firefox。 我試圖將“ Alt + Esc”發送到瀏覽器以使其在啟動時最小化。 但是,firefox始終在其地址欄中鍵入“ {%ESC}”。 我該怎么辦? 謝謝。

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

我用它來打開一個新窗口(使用鍵盤輸入),它工作得很好

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

我更喜歡:

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

現在您可以專注於元素,而不僅僅是Webdriver

發送常規密鑰使用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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM