electron-userland / spectron

DEPRECATED: 🔎 Test Electron apps using ChromeDriver
http://electronjs.org/spectron
MIT License
1.68k stars 229 forks source link

setValue doesn't work after update to spectron 6 #369

Open FomerMay opened 5 years ago

FomerMay commented 5 years ago

Hi, we updated from spectron 5 to 6 (and from electron 2 to 4).

Unfortunately setValue doesn't work anymore for some fields e.g.

<input _ngcontent-c3="" class="text-box text-box_with-clear-button ng-pristine ng-valid ng-touched" crautofocus="" formcontrolname="someName" id="someId" maxlength="50" type="search" placeholder="some Placeholder">

other fields work just fine

<input _ngcontent-c4="" class="form-field__input text-box text-box_with-clear-button ng-untouched ng-pristine ng-valid" e2e-id="e2e-id" formcontrolname="name" id="name" type="search">

we used

await client.element(selector).setValue(value);

now we use as a workaround

await client.element(selector).click(); await client.clearElement(selector); await client.element(selector).keys(value);

any idea what could be the cause?

HaNdTriX commented 4 years ago

I just tested it. The issue I am having is that setValue now appends instead of replacing the value.

Send a sequence of key strokes to an element (clears value before). If the element doesn't need to be cleared first then use addValue. You can also use unicode characters like Left arrow or Back space. WebdriverIO will take care of translating them into unicode characters. You’ll find all supported characters here. To do that, the value has to correspond to a key from the table.

https://webdriver.io/docs/api/element/setValue.html

ciokan commented 4 years ago

Same with spectron 9/electron 7

jesusiglesias commented 4 years ago

Any new update? Same issue with Spectron 10.0.1 and Electron 8.0.0

jesusiglesias commented 4 years ago

I just tested it. The issue I am having is that setValue now appends instead of replacing the value.

Send a sequence of key strokes to an element (clears value before). If the element doesn't need to be cleared first then use addValue. You can also use unicode characters like Left arrow or Back space. WebdriverIO will take care of translating them into unicode characters. You’ll find all supported characters here. To do that, the value has to correspond to a key from the table.

https://webdriver.io/docs/api/element/setValue.html

Yes, the issue is only reproducible when the input has a placeholder/default value. Therefore, the new value is appended to the default one.

jesusiglesias commented 4 years ago

The solution to continue using the setValue() method when the input has a default value or another one is to clear the input previously by sending a backspace key, that is:

await client.element(identifier).keys(["Control", "a", "\uE003", "NULL"]).pause(500).setValue(identifier, value)

Therefore, the clearElement() method is not properly working because it has a wrong behaviour in some cases.

Another way to clear the input is to get the value and overwrite it with backspaces. See link at: https://github.com/webdriverio/webdriverio/issues/1140