在Selenium WebDriver中按Ctrl + A [英] Pressing Ctrl + A in Selenium WebDriver

查看:86
本文介绍了在Selenium WebDriver中按Ctrl + A的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Selenium WebDriver按 Ctrl + A 键?

Is there a way to press the Ctrl + A keys using Selenium WebDriver?

我检查了Selenium库,发现Selenium允许按特殊键和功能键.

I checked the Selenium libraries and found that Selenium allows key press of special and function keys only.

推荐答案

另一个解决方案(在Java中,因为您没有告诉我们您的语言-但对于使用Keys类的所有语言,其工作方式都相同):

One more solution (in Java, because you didn't tell us your language - but it works the same way in all languages with Keys class):

String selectAll = Keys.chord(Keys.CONTROL, "a");
driver.findElement(By.whatever("anything")).sendKeys(selectAll);

您可以使用它来选择<input>或整个页面中的整个文本(只需找到html元素并将其发送给它即可).

You can use this to select the whole text in an <input>, or on the whole page (just find the html element and send this to it).

对于使用Selenium Ruby绑定:

For using Selenium Ruby bindings:

chord()方法> Keys在Ruby绑定中.因此,根据Hari Reddy的建议,您必须使用Selenium Advanced用户交互API,请参见

There's no chord() method in the Keys class in Ruby bindings. Therefore, as suggested by Hari Reddy, you'll have to use Selenium Advanced user interactions API, see ActionBuilder:

    driver.action.key_down(:control)
                 .send_keys("a")
                 .key_up(:control)
                 .perform

这篇关于在Selenium WebDriver中按Ctrl + A的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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