我如何发送键和弦文本区域与硒? [英] How can I send key chords to text area with Selenium?

查看:178
本文介绍了我如何发送键和弦文本区域与硒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想模拟用户按下一个文本区域移进。这里是我一起工作的代码:

I would like to simulate a user pressing shift-enter in a text area. Here is the code I am working with:

var driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://pagewithtextarea");
var textarea = driver.FindElement(By.Id("myTextArea"));
//Send text
textarea.SendKeys("hello world!");

如果我想模拟按下回车键,我可以说

If I want to simulate pressing the enter button I can say

textarea.SendKeys(Keys.Enter);



我怎么可以模拟按住SHIFT键,并输入在同一时间?

How could I simulate pressing shift and enter at the same time?

推荐答案

比我预想的简单。由于的SendKeys接受一个字符串,并在按键的静态常量是他们可以简单地连接在一起这样所有字符串:

Simpler than I expected. Since SendKeys takes a string, and the static constants on Keys are all strings they can simply be concatenated together like this:

textarea.SendKeys(Keys.Shift + Keys.Enter);

这篇关于我如何发送键和弦文本区域与硒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆