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
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();
}
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"), "");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With