Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why .sendKeys(Keys.chord(Keys.CONTROL, "a")) does not work in Chrome

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

This is my code:

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?

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

like image 671
yashaka Avatar asked Oct 28 '25 08:10

yashaka


2 Answers

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();

}
like image 178
Johnny Avatar answered Oct 30 '25 14:10

Johnny


public void copyToClipbord(String copyTo)
{
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    StringSelection str = new StringSelection(copyTo);
    clipboard.setContents(str, null );
}

public void setText(WebElement element, String value)
{
    copyToClipbord(value);
    element.click();
    element.sendKeys(Keys.chord(Keys.CONTROL, "v"), "");
}
like image 20
Mallikarjun Avatar answered Oct 30 '25 15:10

Mallikarjun