本文介绍了为什么 .sendKeys(Keys.chord(Keys.CONTROL, “a")) 在 Chrome 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在文本字段中选择文本并将其删除.我在 linux 上使用 chromedriver.

I am trying to select text in the text field and delete it. I use chromedriver for linux.

这是我的代码:

loginPage.getPasswordField().sendKeys(Keys.chord(Keys.CONTROL, "a"));
loginPage.getPasswordField().sendKeys(Keys.DELETE);

但它不起作用(实际上是第一行).为什么?如何让它发挥作用?

But it does not work (actually first line). Why? How to make it work?

版本:Chrome:版本 28.0.1500.95ChromeDriver:chromedriver_linux64_2.1/chromedriver_linux64_2.2

Versions:Chrome: Version 28.0.1500.95ChromeDriver: chromedriver_linux64_2.1/chromedriver_linux64_2.2

推荐答案

您是否尝试过使用动作生成器?例如,来自我们的自动化套件:

Have you tried to use action builder?For example, from our automation suite:

public void selectAndDeleteTextViaKeyboard() {
    selectTextViaKeyboard()
    deleteViaKeyboard() 
}

public void deleteViaKeyboard() {
    Actions builder = new Actions(webDriverProxy.getWebDriver());
    builder.sendKeys(Keys.DELETE)
            .release().perform();
}

public void selectTextViaKeyboard() {
    Actions builder = new Actions(webDriverProxy.getWebDriver());
    Action select= builder
            .keyDown(Keys.CONTROL)
            .sendKeys("a")
            .keyUp(Keys.CONTROL)
            .build();
    select.perform();

}

这篇关于为什么 .sendKeys(Keys.chord(Keys.CONTROL, “a")) 在 Chrome 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 06:34