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

WebElementFacadeImpl.clear method does not work properly #2038

Closed
martinsefcik opened this issue Apr 20, 2020 · 11 comments
Closed

WebElementFacadeImpl.clear method does not work properly #2038

martinsefcik opened this issue Apr 20, 2020 · 11 comments

Comments

@martinsefcik
Copy link
Contributor

There were some changes made recently in clear method in #1788, but I guess it still does not work as expected, because when the test is running locally e.g. under Mac but against Selenium Grid hub or against Browserstack and target OS is different e.g. Windows then incorrect shortcut is used for selecting all text and the result of clear method is that key 'a' is entered into text field.

So I guess this clear method should not check local OS type but target OS type to distinguish which shortcut combination should be used.

Tested using version 2.2.1

@wakaleo
Copy link
Member

wakaleo commented Apr 20, 2020

Could you propose a PR?

@martinsefcik
Copy link
Contributor Author

martinsefcik commented Apr 20, 2020

@wakaleo I can try, but I'm not sure I will be able to do it. I will need some hint at least how to start.
Is the some possibility how to get remote OS type e.g from driver ?

@wakaleo
Copy link
Member

wakaleo commented Apr 20, 2020

Yeah, knowing the remote OS in a general case would be very tricky. Maybe find another general way to clear a text field? I suspect the current approach was done because the intuitive approach (eg use clear()m) doesn’t work.

@martinsefcik
Copy link
Contributor Author

proposal 1:
Ugly but general solution would be to press backspace many times based text length ... not usable for textareas with large texts - can be very slow.

proposal 2:
Another ugly solution would be to always (on all OSes) use both combinations in following order:

  1. CMD+a and DELETE
  2. CTRL+a and DELETE
    must be in this order because CTRL+a does nothing (only moves cursor at the beginning of textarea) on Mac but CMD+a prints a on Windows

It would be better to find some nicer solution, but if it is not possible to get easily target OS type then I don't know how to do it.

@wakaleo
Copy link
Member

wakaleo commented Apr 22, 2020

Knowing the target OS will depend on the remote server being used, so does not seem possible in a general case. I think ugly solution #2 would be the least worse.

@arustamov
Copy link
Contributor

arustamov commented Feb 4, 2022

Hi @wakaleo,

Noticed today serenity clear method implementation stopped working for me and my colleagues in Chrome 97+
It produces some special characters entered instead of getting the input element value blank
Compared to the selenoid instance where I have chrome version 92 defined. Works fine there. Works fine in firefox as well

Had to switch to the following to resolve the issue:
getJavascriptExecutorFacade().executeScript("arguments[0].value = '';", element);

Wonder if you or anyone else experienced the same?

Screenshot 2022-02-04 at 20 12 00

Screenshot 2022-02-04 at 20 13 14

Screenshot 2022-02-04 at 20 14 04

Screenshot 2022-02-04 at 20 14 16

@wakaleo
Copy link
Member

wakaleo commented Feb 4, 2022

I noticed this today too - I'll push a fix in the next release.

@wakaleo
Copy link
Member

wakaleo commented Feb 12, 2022

Fixed in 3.2.0

@wakaleo wakaleo closed this as completed Feb 12, 2022
@HajekOndrej
Copy link

Hi @wakaleo, sorry to hijack this, but I think it may be related... in commit you have removed the element content clearing workaround in WebElementFacadeImpl (lines 1274-1276) stating that it's no longer needed. I have recently run into issue with this, that the .clear() method doesn't really work without this, so I had to add the workaround to my code. Is that expected?

@wakaleo
Copy link
Member

wakaleo commented Oct 6, 2022

Hi @wakaleo, sorry to hijack this, but I think it may be related... in commit you have removed the element content clearing workaround in WebElementFacadeImpl (lines 1274-1276) stating that it's no longer needed. I have recently run into issue with this, that the .clear() method doesn't really work without this, so I had to add the workaround to my code. Is that expected?

Dunno, I don't do mobile. Feel free to put it back with a PR if it is needed.

@HajekOndrej
Copy link

Hi @wakaleo, sorry to hijack this, but I think it may be related... in commit you have removed the element content clearing workaround in WebElementFacadeImpl (lines 1274-1276) stating that it's no longer needed. I have recently run into issue with this, that the .clear() method doesn't really work without this, so I had to add the workaround to my code. Is that expected?

Dunno, I don't do mobile. Feel free to put it back with a PR if it is needed.

Thanks for your quick reply.
Correct me if I am wrong, but the workaround was there for NOT mobile. The problem manifests in Chrome.

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

No branches or pull requests

4 participants