Selenium: sendKeysQuickly implementation

Created on 15 Jan 2020  路  11Comments  路  Source: SeleniumHQ/selenium

馃殌 Feature Proposal

sendKeysQuickly implementation could paste the entire text all at once instead of character by character.

Motivation

sendKeys is too slow if the text is very long.

Example

String value = "...very long text...";
WebElement element = ...
element.sendKeys(value);
C-java

Most helpful comment

The implementation proposed in the referenced PR:
1) uses local clipboard and can't paste from it to a remote browser,
2) even locally can work if the browser window is in focus only.

So we hardly can accept it, sorry.

All 11 comments

you can do such a thing faster using javascript executor

@symonk, I know, and that's why I'm asking for a new feature in selenium. So as not to be forced to use the javascript executor

To implement this in a non-JS manner the WebDriver spec would probably need to be updated to specify paste behavior due to the current security requirements around the clipboard api

    String value = "...very long text..."; 
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(value), null);
    WebElement element = ... 
    element.sendKeys(Keys.CONTROL , "v");

@sgrillon14 Which browsers are you expecting that to work for? It's not going to be supported by Selenium cross-browser without some sort of definition in the WebDriver spec.

The implementation proposed in the referenced PR:
1) uses local clipboard and can't paste from it to a remote browser,
2) even locally can work if the browser window is in focus only.

So we hardly can accept it, sorry.

The idea per se is not bad. But the proposed implementation is too naive. A more robust implementation should be based on the browser API that allows accessing clipboard (see [1]), but it's not easy to use due to security restrictions. A new protocol command should be added and implemented in selenium server too.

[1] https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard

@barancev, OK. Have you an idea? is it possible send char by char but more quikly?

This should ideally be done as a wrapper around Selenium. There are ways that you can do this via executeJavaScript or what was mentioned in https://github.com/SeleniumHQ/selenium/issues/7937#issuecomment-576678181.

Thanks for the idea

@AutomatedTester, #7937 (comment) is only a workaround. Sometimes the target Web interface do not detect change by javascript.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings