webdriverio icon indicating copy to clipboard operation
webdriverio copied to clipboard

setValue() doesn't clear input before setting new value

Open ghost opened this issue 10 years ago • 44 comments

In my test case I have a step where new value is set to a non empty input (with type number). According to webdriverIO API, the setValue method should clear an input at first and then should type a new value. But in my case, setValue appends new value to existing one.

I'm using webdriverIO 3.4.0 with Selenium standalone server 2.52.0 and Firefox 44.0.2. The forms in my application under test are created with React.js library.

ghost avatar Mar 02 '16 12:03 ghost

Could you post the selenium logs of that part where you use setValue?

christian-bromann avatar Mar 02 '16 17:03 christian-bromann

Sure, here it is that part of selenium log:

12:16:04.077 INFO - Done: [clear: 17 [[FirefoxDriver: firefox on WINDOWS (2009724f-387c-4e20-8dc2-92df612798a8)] -> xpath: (//button[.="Przesy?ka kurierska"]/../..//input)[3]]]
12:16:04.081 INFO - Executing: [send keys: 17 [[FirefoxDriver: firefox on WINDOWS (2009724f-387c-4e20-8dc2-92df612798a8)] -> xpath: (//button[.="Przesy?ka kurierska"]/../..//input)[3]], [5]])
12:16:04.104 INFO - Done: [clear: 18 [[FirefoxDriver: firefox on WINDOWS (2009724f-387c-4e20-8dc2-92df612798a8)] -> xpath: (//button[.="List polecony ekonomiczny"]/../..//input)[3]]]
12:16:04.110 INFO - Executing: [send keys: 18 [[FirefoxDriver: firefox on WINDOWS (2009724f-387c-4e20-8dc2-92df612798a8)] -> xpath: (//button[.="List polecony ekonomiczny"]/../..//input)[3]], [5]])
12:16:04.135 INFO - Done: [clear: 19 [[FirefoxDriver: firefox on WINDOWS (2009724f-387c-4e20-8dc2-92df612798a8)] -> xpath: (//button[.="List polecony priorytetowy"]/../..//input)[3]]]
12:16:04.140 INFO - Executing: [send keys: 19 [[FirefoxDriver: firefox on WINDOWS (2009724f-387c-4e20-8dc2-92df612798a8)] -> xpath: (//button[.="List polecony priorytetowy"]/../..//input)[3]], [1, 0]])

ghost avatar Mar 03 '16 11:03 ghost

I am seeing the same problem. The inputs are not cleared (not with setValue() and not with clearElement() either). New values are appended.

12:41:57.165 INFO - Executing: [find elements: By.cssSelector: input[name=email]])
12:41:57.183 INFO - Done: [find elements: By.cssSelector: input[name=email]]
12:41:57.191 INFO - Executing: [clear: 3 [[ChromeDriver: chrome on MAC (1f3151b777f3aaf6b39852c72fc62d1a)] -> css selector: input[name=email]]])
12:41:57.219 INFO - Done: [clear: 3 [[ChromeDriver: chrome on MAC (1f3151b777f3aaf6b39852c72fc62d1a)] -> css selector: input[name=email]]]
12:41:57.227 INFO - Executing: [send keys: 3 [[ChromeDriver: chrome on MAC (1f3151b777f3aaf6b39852c72fc62d1a)] -> css selector: input[name=email]], [t, e, s, t, @, t, e, s, t, ., t, e, s, t]])
12:41:57.295 INFO - Done: [send keys: 3 [[ChromeDriver: chrome on MAC (1f3151b777f3aaf6b39852c72fc62d1a)] -> css selector: input[name=email]], [t, e, s, t, @, t, e, s, t, ., t, e, s, t]]

I am using webdriverio 4.0.3 and mercury for rendering the html.

ishristov avatar Mar 08 '16 10:03 ishristov

It seems that the command gets executed successful though. Seems to be a Chromedriver issue then.

christian-bromann avatar Mar 08 '16 11:03 christian-bromann

Faced the same problem. Input was not cleared with neither clearElement() nor setValue().

However, it starts working for me when I click the input or write something just before clearing (i'm using cucumberjs - and for some strange reason it does not work when I click/write in the same step, but works fine if I do this in previous step).

P.S. I'm using selenium: "2.48.2", chromedriver: "2.20", webdriverio: "2.4.5". ReactJS.

ifilatov avatar Mar 21 '16 18:03 ifilatov

Could you update the selenium standalone server and try again?

christian-bromann avatar Apr 06 '16 23:04 christian-bromann

@adolatowska I have just run simple test (see below) with the same webdriverio version, same selenium standalone server, but different FF (45.0.1) and it works fine for me. FYI @christian-bromann

var webdriverio = require('../webdriverio');
var options = {
    desiredCapabilities: {
        browserName: 'firefox'
    }
};

webdriverio
    .remote(options)
    .init()
    .url('http://www.google.co.uk')
    .setValue('#lst-ib', 'test')
    .pause(5000)
    .setValue('#lst-ib', 'arek')
    .pause(5000)
    .end();

Selenoum Logs below

14:05:56.883 INFO - Selenium Server is up and running
14:06:03.154 INFO - Executing: [new session: Capabilities [{rotatable=true, locationContextEnabled=true, loggingPrefs=org.openqa.selenium.logging.LoggingPreferences@6de9b74d, browserName=firefox, javascriptEnabled=true, handlesAlerts=true, version=, platform=ANY, requestOrigins={name=webdriverio, version=3.4.0, url=http://webdriver.io}}]])
14:06:03.171 INFO - Creating a new session for Capabilities [{rotatable=true, locationContextEnabled=true, loggingPrefs=org.openqa.selenium.logging.LoggingPreferences@6de9b74d, browserName=firefox, javascriptEnabled=true, handlesAlerts=true, version=, platform=ANY, requestOrigins={name=webdriverio, version=3.4.0, url=http://webdriver.io}}]
14:06:06.831 INFO - Done: [new session: Capabilities [{rotatable=true, locationContextEnabled=true, loggingPrefs=org.openqa.selenium.logging.LoggingPreferences@6de9b74d, browserName=firefox, javascriptEnabled=true, handlesAlerts=true, version=, platform=ANY, requestOrigins={name=webdriverio, version=3.4.0, url=http://webdriver.io}}]]
14:06:06.852 INFO - Executing: [get: http://www.google.co.uk])
14:06:08.377 INFO - Done: [get: http://www.google.co.uk]
14:06:08.410 INFO - Executing: [find elements: By.id: lst-ib])
14:06:08.514 INFO - Done: [find elements: By.id: lst-ib]
14:06:08.530 INFO - Executing: [clear: 0 [[FirefoxDriver: firefox on MAC (5649de47-170c-d74d-b813-018cfa7da030)] -> id: lst-ib]])
14:06:08.623 INFO - Done: [clear: 0 [[FirefoxDriver: firefox on MAC (5649de47-170c-d74d-b813-018cfa7da030)] -> id: lst-ib]]
14:06:08.633 INFO - Executing: [send keys: 0 [[FirefoxDriver: firefox on MAC (5649de47-170c-d74d-b813-018cfa7da030)] -> id: lst-ib], [t, e, s, t]])
14:06:08.716 INFO - Done: [send keys: 0 [[FirefoxDriver: firefox on MAC (5649de47-170c-d74d-b813-018cfa7da030)] -> id: lst-ib], [t, e, s, t]]
14:06:13.729 INFO - Executing: [find elements: By.id: lst-ib])
14:06:13.741 INFO - Done: [find elements: By.id: lst-ib]
14:06:13.750 INFO - Executing: [clear: 0 [[FirefoxDriver: firefox on MAC (5649de47-170c-d74d-b813-018cfa7da030)] -> id: lst-ib]])
14:06:13.780 INFO - Done: [clear: 0 [[FirefoxDriver: firefox on MAC (5649de47-170c-d74d-b813-018cfa7da030)] -> id: lst-ib]]
14:06:13.787 INFO - Executing: [send keys: 0 [[FirefoxDriver: firefox on MAC (5649de47-170c-d74d-b813-018cfa7da030)] -> id: lst-ib], [a, r, e, k]])
14:06:13.851 INFO - Done: [send keys: 0 [[FirefoxDriver: firefox on MAC (5649de47-170c-d74d-b813-018cfa7da030)] -> id: lst-ib], [a, r, e, k]]
14:06:18.861 INFO - Executing: [delete session: f39e1174-0b7a-42b2-9d9d-1ac3505416f8])
14:06:19.596 INFO - Done: [delete session: f39e1174-0b7a-42b2-9d9d-1ac3505416f8]

pi4r0n avatar Apr 12 '16 13:04 pi4r0n

I've tested again with Selenium Standalone version 2.53.0 and both FF versions: 45.0.1 and 45.0.2. Situation is the same. Here is Selenium log from run on FF v.45.0.1:


> 19:26:55.659 INFO - Executing: [clear: 22 [[FirefoxDriver: firefox on WINDOWS (c9c978bb-acc5-4693-a830-5676e4c0b35d)] -> xpath: (//button[.="Przesy?ka kurierska"]/../..//input)[3]]])
> 19:26:55.664 INFO - Done: [find elements: By.xpath: (//button[.="List polecony ekonomiczny"]/../..//input)[3]]
> 19:26:55.671 INFO - Executing: [clear: 23 [[FirefoxDriver: firefox on WINDOWS (c9c978bb-acc5-4693-a830-5676e4c0b35d)] -> xpath: (//button[.="List polecony ekonomiczny"]/../..//input)[3]]])
> 19:26:55.677 INFO - Done: [find elements: By.xpath: (//button[.="List polecony priorytetowy"]/../..//input)[3]]
> 19:26:55.684 INFO - Executing: [clear: 24 [[FirefoxDriver: firefox on WINDOWS (c9c978bb-acc5-4693-a830-5676e4c0b35d)] -> xpath: (//button[.="List polecony priorytetowy"]/../..//input)[3]]])
> 19:26:55.700 INFO - Done: [clear: 22 [[FirefoxDriver: firefox on WINDOWS (c9c978bb-acc5-4693-a830-5676e4c0b35d)] -> xpath: (//button[.="Przesy?ka kurierska"]/../..//input)[3]]]
> 19:26:55.704 INFO - Executing: [send keys: 22 [[FirefoxDriver: firefox on WINDOWS (c9c978bb-acc5-4693-a830-5676e4c0b35d)] -> xpath: (//button[.="Przesy?ka kurierska"]/../..//input)[3]], [5]])
> 19:26:55.721 INFO - Done: [clear: 23 [[FirefoxDriver: firefox on WINDOWS (c9c978bb-acc5-4693-a830-5676e4c0b35d)] -> xpath: (//button[.="List polecony ekonomiczny"]/../..//input)[3]]]
> 19:26:55.726 INFO - Executing: [send keys: 23 [[FirefoxDriver: firefox on WINDOWS (c9c978bb-acc5-4693-a830-5676e4c0b35d)] -> xpath: (//button[.="List polecony ekonomiczny"]/../..//input)[3]], [5]])
> 19:26:55.741 INFO - Done: [clear: 24 [[FirefoxDriver: firefox on WINDOWS (c9c978bb-acc5-4693-a830-5676e4c0b35d)] -> xpath: (//button[.="List polecony prioryteto
> wy"]/../..//input)[3]]]
> 19:26:55.745 INFO - Executing: [send keys: 24 [[FirefoxDriver: firefox on WINDOWS (c9c978bb-acc5-4693-a830-5676e4c0b35d)] -> xpath: (//button[.="List polecony priorytetowy"]/../..//input)[3]], [1, 0]])
> 19:26:55.780 INFO - Done: [send keys: 22 [[FirefoxDriver: firefox on WINDOWS (c9c978bb-acc5-4693-a830-5676e4c0b35d)] -> xpath: (//button[.="Przesy?ka kurierska"]/../..//input)[3]], [5]]
> 19:26:55.814 INFO - Done: [send keys: 23 [[FirefoxDriver: firefox on WINDOWS (c9c978bb-acc5-4693-a830-5676e4c0b35d)] -> xpath: (//button[.="List polecony ekonomiczny"]/../..//input)[3]], [5]]
> 19:26:55.859 INFO - Done: [send keys: 24 [[FirefoxDriver: firefox on WINDOWS (c9c978bb-acc5-4693-a830-5676e4c0b35d)] -> xpath: (//button[.="List polecony priorytetowy"]/../..//input)[3]], [1, 0]]

and here is log from run on FF v. 45.0.2:


> 19:31:35.154 INFO - Executing: [clear: 22 [[FirefoxDriver: firefox on WINDOWS (a1c5eedb-cbcb-40af-8c64-142651c20683)] -> xpath: (//button[.="List polecony priorytetowy"]/../..//input)[3]]])
> 19:31:35.160 INFO - Done: [find elements: By.xpath: (//button[.="List polecony ekonomiczny"]/../..//input)[3]]
> 19:31:35.165 INFO - Executing: [clear: 23 [[FirefoxDriver: firefox on WINDOWS (a1c5eedb-cbcb-40af-8c64-142651c20683)] -> xpath: (//button[.="List polecony ekonomiczny"]/../..//input)[3]]])
> 19:31:35.176 INFO - Done: [find elements: By.xpath: (//button[.="Przesy?ka kurierska"]/../..//input)[3]]
> 19:31:35.181 INFO - Executing: [clear: 24 [[FirefoxDriver: firefox on WINDOWS (a1c5eedb-cbcb-40af-8c64-142651c20683)] -> xpath: (//button[.="Przesy?ka kurierska"]/../..//input)[3]]])
> 19:31:35.199 INFO - Done: [clear: 22 [[FirefoxDriver: firefox on WINDOWS (a1c5eedb-cbcb-40af-8c64-142651c20683)] -> xpath: (//button[.="List polecony priorytetowy"]/../..//input)[3]]]
> 19:31:35.204 INFO - Executing: [send keys: 22 [[FirefoxDriver: firefox on WINDOWS (a1c5eedb-cbcb-40af-8c64-142651c20683)] -> xpath: (//button[.="List polecony priorytetowy"]/../..//input)[3]], [1, 0]])
> 19:31:35.219 INFO - Done: [clear: 23 [[FirefoxDriver: firefox on WINDOWS (a1c5eedb-cbcb-40af-8c64-142651c20683)] -> xpath: (//button[.="List polecony ekonomiczny"]/../..//input)[3]]]
> 19:31:35.223 INFO - Executing: [send keys: 23 [[FirefoxDriver: firefox on WINDOWS (a1c5eedb-cbcb-40af-8c64-142651c20683)] -> xpath: (//button[.="List polecony ekonomiczny"]/../..//input)[3]], [5]])
> 19:31:35.239 INFO - Done: [clear: 24 [[FirefoxDriver: firefox on WINDOWS (a1c5eedb-cbcb-40af-8c64-142651c20683)] -> xpath: (//button[.="Przesy?ka kurierska"]/../..//input)[3]]]
> 19:31:35.244 INFO - Executing: [send keys: 24 [[FirefoxDriver: firefox on WINDOWS (a1c5eedb-cbcb-40af-8c64-142651c20683)] -> xpath: (//button[.="Przesy?ka kurierska"]/../..//input)[3]], [5]])
> 19:31:35.298 INFO - Done: [send keys: 22 [[FirefoxDriver: firefox on WINDOWS (a1c5eedb-cbcb-40af-8c64-142651c20683)] -> xpath: (//button[.="List polecony priorytetowy"]/../..//input)[3]], [1, 0]]
> 19:31:35.337 INFO - Done: [send keys: 23 [[FirefoxDriver: firefox on WINDOWS (a1c5eedb-cbcb-40af-8c64-142651c20683)] -> xpath: (//button[.="List polecony ekonomiczny"]/../..//input)[3]], [5]]
> 19:31:35.372 INFO - Done: [send keys: 24 [[FirefoxDriver: firefox on WINDOWS (a1c5eedb-cbcb-40af-8c64-142651c20683)] -> xpath: (//button[.="Przesy?ka kurierska"]/../..//input)[3]], [5]]

ghost avatar Apr 12 '16 18:04 ghost

@adolatowska / @christian-bromann is it just me or "clear" send to (//button[.="Przesy?ka kurierska"]/../..//input)[3]]]) but "send keys" to (//button[.="Przesy?ka kurierska"]/../..//input)[3]]

Notice the extra " ] " in clear command at the end. It would explain, why its not clearing the values.

pi4r0n avatar Apr 13 '16 08:04 pi4r0n

@adolatowska can you try to use a different selector?

christian-bromann avatar Apr 13 '16 08:04 christian-bromann

Closing due to inactivity. I am happy to open this again, if this is still valid.

christian-bromann avatar Oct 25 '16 16:10 christian-bromann

I also have the same issue with FF 47-49

mikhailpractice avatar Dec 05 '16 22:12 mikhailpractice

I am having the same problem with both Firefox 53.0.2 and Chrome 58.0.3029.110 and selenium-standalone 6.4.1. I'm testing against a React app, if that helps at all.

jkwaldrip avatar May 12 '17 15:05 jkwaldrip

I'm adding a resolution here and on #891 for the workaround I used. It looks like our React DOM isn't updating whenever an element is cleared with .clearElement() and then set again with .setValue(), so I had to backspace out the field one character at a time:

let x = browser.getValue(selector);
for (let i = 0; i < x.length; i++) { browser.setValue(selector, "\uE003").pause(100); };
browser.setValue(selector, newValue);

jkwaldrip avatar May 15 '17 16:05 jkwaldrip

@jkwaldrip This workaround didn't work for me. We use react-redux for our front end and using setValue the value is always appended even if I clear the field using clearElement(). or with backspaces as given in your code above.Any other steps I can try?

swetashahi avatar Aug 08 '17 18:08 swetashahi

Has there been any solution yet. I am still seeing the same issue. Here is my configuration

"wdio-chromedriver-service": "^0.1.2",
"webdriverio": "^4.8.0"

selenium-server-standalone-2.53.1.jar

sbukke1 avatar Aug 03 '18 03:08 sbukke1

Same issue here. Selenium Server 3.14.0 Chromedriver 2.41

MartinX3 avatar Aug 30 '18 13:08 MartinX3

Same issue re-introduced here after upgrading to Chromedriver 2.43 - now have to rely on @jkwaldrip's suggestion with backspacing.

2hansen avatar Oct 25 '18 10:10 2hansen

Please try this, it worked for me We first need to put the focus on the element, then clear it and then write stuff on it.

.click('input[aria-label=Login]') // Workaround to make .clearValue() possible.
.clearValue('input[aria-label=Login]') // Without clearValue() the value would be appended.
.setValue('input[aria-label=Login]', 'new_value')

MartinX3 avatar Oct 25 '18 14:10 MartinX3

That was what I did until today, where I updated to latest Chromedriver, and it stopped working.

2hansen avatar Oct 25 '18 14:10 2hansen