Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chrome 71 [ClearText does not work for REACT input box] #6741

Closed
ckzgraphics opened this issue Dec 11, 2018 · 11 comments
Closed

Chrome 71 [ClearText does not work for REACT input box] #6741

ckzgraphics opened this issue Dec 11, 2018 · 11 comments

Comments

@ckzgraphics
Copy link

🐛 Bug Report

While running test against a REACT webpage on Chrome 71 + Windows 10, 'clear text' command does not clear the input box contents.

To Reproduce

Detailed steps to reproduce the behavior:

[In Chrome 71 + Windows 10]

  1. Open URL- https://foxhound87.github.io/mobx-react-form-demo/dem
  2. Use 'Clear Text' command (POST /session/<SESSION_ID>/element/<ELEMENT_ID>/clear)

Expected behavior

The text should be cleared from the text box.

Test script or set of commands reproducing this issue

You can use the following GIST to replicate the issue- https://gist.github.com/ckzgraphics/418cf54ed3a60f057fcc0834e9bef010

BrowserStack Session [executed on REACT webpage][FAILED]- a21750b06f9ec90ccc35c62c7f83da534bb7b253

Selenium Logs (for the above session)- https://gist.github.com/ckzgraphics/1968040180812899dc771df69ff5f7eb

BrowserStack Session [executed on SIMPLE webpage][PASSED]- e3f6831f153a002d874a6fcc50ee37f8feeaadb2

Selenium Logs (for the above session)- https://gist.github.com/ckzgraphics/1589742d8ca96836018237e1057548e9

Environment

OS: Windows 10
Browser: Chrome
Browser version: 71
Browser Driver version: 2.44

Language Bindings version:
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

Selenium Grid version (if applicable): 3.14.0

@yboi
Copy link

yboi commented Dec 13, 2018

The same an issue when using pytest.

@barancev
Copy link
Member

Yes, this input is tricky...

      WebElement ele = webDriver.findElement(By.xpath(".//input[@name='username']"));
      new Actions(webDriver).click(ele)
        .pause(200).keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL)
        .pause(200).sendKeys(Keys.BACK_SPACE)
        .pause(200).sendKeys("KOOKOK").perform();

@barancev
Copy link
Member

In debugger, step by step, you can see that selenium clears the input, but later the application restores its value. The reason is simple: clear operation is not fair, it does not match any human user action. Selenium is cheating to clear an input, but this cheating does not work for sophisticated fields with intelligent event handlers. So you have to act like a human user, that is what Actions class is intended for.

@ckzgraphics
Copy link
Author

ckzgraphics commented Dec 13, 2018

In debugger, step by step, you can see that selenium clears the input, but later the application restores its value. The reason is simple: clear operation is not fair, it does not match any human user action. Selenium is cheating to clear an input, but this cheating does not work for sophisticated fields with intelligent event handlers. So you have to act like a human user, that is what Actions class is intended for.

I am using 'ele.clear();' not the Action class!! The same works properly on older Chrome browser. You think I should raise this in Chromium project?

@barancev
Copy link
Member

That's exactly what I told, ele.clear() does not work. Or, it works (you can see it in debugger), it clears the field for some time, but later the application restores the original value. I suppose this command does not fire some event required for "persistent" cleaning. And it does not work in all browsers (I checked Firefox and IE).

Yes, it's a driver (e.g. chromedriver) issue, but may be it's a specification issue too (https://w3c.github.io/webdriver/#element-clear)

Try to raise an issue on chromedriver tracker, let them see if it is an implementation or a specification issue.

@ckzgraphics
Copy link
Author

The behaviour was logged on Chromium(Chromedriver)[2702]

@yboi
Copy link

yboi commented Dec 14, 2018

barancev можеш дать линк на автомейш чат? раньше юзал, но потерял

@mushtaqsayyed
Copy link

mushtaqsayyed commented Dec 17, 2018

Using the following workaround resolved the behaviour-

driver.findElement(By.name("username")).sendKeys(Keys.chord(Keys.CONTROL,"a", Keys.DELETE));

@barancev
Copy link
Member

@sjethvani
Copy link

I am having angular input tag , which wasn't getting cleared using driver.findElement().clear() in chrome V71 (chrome driver 2.45) . I used below code , which worked for me

WebElement ele = webDriver.findElement(By.xpath(".//input[@name='username']")); 
new Actions(webDriver).click(element).sendKeys(Keys.END).keyDown(Keys.SHIFT).sendKeys(Keys.HOME).keyUp(Keys.SHIFT).sendKeys(Keys.BACK_SPACE).sendKeys("").perform()

@aleksandr-kotlyar
Copy link

aleksandr-kotlyar commented May 19, 2019

Hello friends!
I want to share with you my solution for history, even if the issue is closed.
Alexei's @barancev variant didn't work for my current project react app and password input field.

      WebElement ele = webDriver.findElement(By.xpath(".//input[@name='username']"));
      new Actions(webDriver).click(ele)
        .pause(200).keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL)
        .pause(200).sendKeys(Keys.BACK_SPACE)

And yesterday i have created my own solution, which works:

while field_password().get_attribute('value') != '':
    field_password().send_keys(Keys.BACKSPACE)

and another variant, still works:

while len(field_password().get_attribute('value')) != 0:
    field_password().send_keys(Keys.BACKSPACE)

where field_password() is a WebElement, or to be fair SeleneElement, from selene library:

def field_password() -> SeleneElement:
    return s('input[name="password"]')

But for pure selenium my solution should also work.

I hope it would help someone someday.

Best regards,
Aleksandr.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants