question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

disable "unfocusing steps" after clear() in SelenideElement#setValue()

See original GitHub issue

GIVEN An application with an input field with the submit handler bound to “blur event” (example: edit field $(".editing .edit") of a task in any app from todomvc.com). WHEN $(".editing .edit").setValue("new task name") THEN: the input field will be:

  • old selenium behaviour (at least till ~ 3.6.0) => the input field will be submitted with "new task name" value
  • new selenium webdriver behavior => the input field will be submitted with "" value and then fail with being unable to set the value to “new task name”.

The reason for that is that previously selenium did not do any “events firing” after clear():

    /*
     * ...
     * Note that the events fired by this event may not be as you'd expect.  In particular, we don't
     * fire any keyboard or mouse events.  If you want to ensure keyboard events are fired, consider
     * using something like {@link #sendKeys(CharSequence...)} with the backspace key.  To ensure
     * you get a change event, consider following with a call to {@link #sendKeys(CharSequence...)}
     * with the tab key.
     */
    void clear();

but now it does according to the w3c standard: image It runs “unfocusing events”…

Somebody does not like this behavior in selenium and considers it as a bug

Somebody really wants this and wants even more events to be fired after clear.

I believe that from the “real user” perspective the new behavior of the clear method in selenium - is ok and really natural. If we consider “clear()” as “atomic user operation” on element - then this is natural to fire corresponding events after it.

But then… if we continue to consider operations from the user perspective, i.e. as if they are “atomic user operations”, then now SelenideElement#setValue is no atomic any more, since it is based on clear() being called before sendKeys()… Continuing this logic, I believe that we should find a way to disable “firing events” after clear() and before sendKeys inside setValue implementation. No need to fire events twice, we need to do that just once at the end of “atomic user operation”, i.e. at the end of setValue()

Potential implementation could be to change “clearing” implementation to be based on js instead of WebElement#clear(). We also can put it under Configuration.clearByJsInsideSetValue or Configuration.fireUnfocusingEventsAfterClearInSetValue or Configuration.someBetterName 😃

P.S. by the way Configuration.fastSetValue can be used as workaround so far… Yet I believe that just existance of fastSetValue is not enough… For me having events being fired twice inside setValue just does not make sense from user perspective…

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
rosolkocommented, Aug 1, 2019

Ok. In such perspective we should perform “select all” and type a new string then. Not a clean + type.

0reactions
asolntsevcommented, Apr 30, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove the focus from an element after setText or sendKeys
Hello everyone,. I am testing a text field set with setText() but after its execution, the focus is still on the element I...
Read more >
Interface SelenideElement
Append given text to the text field and trigger "change" event. SelenideElement ... Clear the input field. void. click(). Click the element. SelenideElement....
Read more >
Selenide. Ввод текста в input. Не стирается предыдущее ...
Issue #1497 · selenide/selenide · GitHub · disable "unfocusing steps" after clear() in SelenideElement#setValue() · Issue #960 · selenide/selenide · GitHub.
Read more >
SelenideElement · Selenide User Guide
Element actions methods: click(); doubleClick(); contextClick(); hover(); setValue(String) | val( ...
Read more >
SelenideElement (workspace 1.11 API) - Javadoc.io
public interface SelenideElement extends org.openqa.selenium.WebElement ... ShouldableWebElement setValue(java.lang.String text) ... WebElement.clear() 2.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found