简体   繁体   English

你如何以编程方式在Selenium C#中按下一个键?

[英]How do you programmatically hold down a key in Selenium C#?

I've been looking for an answer to this, but all of the topics about it was really outdated. 我一直在寻找答案,但所有关于它的主题都已经过时了。

The situation is, I have a flash game on the browser that I'm trying to play programmatically using the arrow keys. 情况是,我在浏览器上有一个flash游戏,我正在尝试使用箭头键以编程方式播放。 I know how to send a signal to the keys though, ex: 我知道如何向键发送信号,例如:

driver.FindElement(By.Id("myflash")).SendKeys(Keys.ArrowLeft);

But can't really get past that part. 但不能真正超越那一部分。

你能尝试使用和弦吗?

driver.FindElement(By.Id("myflash")).sendKeys(Keys.chord(Keys.ARROW_LEFT));

Try using the Actions. 尝试使用Actions。

Try this 尝试这个

new Actions(driver).KeyDown(driver.FindElement(By.Id("myflash")), Keys.ArrowLeft).perform();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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