Re: Issue 214 in selenium: onchange js event fired in WebElement.clear() and WebElement.sendKeys()

1,208 views
Skip to first unread message

sele...@googlecode.com

unread,
Jan 26, 2011, 8:56:42 PM1/26/11
to selenium-deve...@googlegroups.com
Updates:
Cc: jmleyba
Labels: Component-WebDriver

Comment #4 on issue 214 by jari.bakken: onchange js event fired in
WebElement.clear() and WebElement.sendKeys()
http://code.google.com/p/selenium/issues/detail?id=214

This report is quite old. Is this still a problem in 2.0b1?

sele...@googlecode.com

unread,
Jan 27, 2011, 6:49:27 AM1/27/11
to selenium-deve...@googlegroups.com

Comment #5 on issue 214 by jjim...@googlemail.com: onchange js event fired
in WebElement.clear() and WebElement.sendKeys()
http://code.google.com/p/selenium/issues/detail?id=214

Yes, still behaving the same. I still have to use the workaround described
in comment 2. The bug title and report aren't very accurate though.

I'm trying to get consistent behaviour between HTMLUnit and Firefox drivers

WebElement.sendKeys(text) doesn't fire onchange(). I'm happy with that.
WebElement.clear() fires onchange() if the input had a value. Is that
right? It means I can't use it.

org.openqa.selenium.Keys don't work in HTMLUnit (e.g. BACK_SPACE and
TAB). That means I have use the above workaround to change the value of a
input.


sele...@googlecode.com

unread,
Aug 10, 2011, 2:04:37 AM8/10/11
to selenium-deve...@googlegroups.com

Comment #6 on issue 214 by sakthive...@gmail.com: onchange js event fired
in WebElement.clear() and WebElement.sendKeys()
http://code.google.com/p/selenium/issues/detail?id=214

Hi jjim...@googlemail.com,
I ma new to Selenium. I have used Selenium IDE,
and facing many problem, error. Searched in web but could not get clear
notes or idea about the error or Selenium can u give any notes about
Selenium.

Thanks & Regards
Sakthy
(sakth...@gmail.com)

sele...@googlecode.com

unread,
Sep 5, 2011, 3:26:05 PM9/5/11
to selenium-deve...@googlegroups.com

Comment #7 on issue 214 by markkemp...@gmail.com: onchange js event fired
in WebElement.clear() and WebElement.sendKeys()
http://code.google.com/p/selenium/issues/detail?id=214

+1 on this. the Clear() method should not fire any change event until focus
is moved to another element.

sele...@googlecode.com

unread,
Nov 22, 2011, 9:40:19 AM11/22/11
to selenium-deve...@googlegroups.com

Comment #8 on issue 214 by milan.vo...@gmail.com: onchange js event fired
in WebElement.clear() and WebElement.sendKeys()
http://code.google.com/p/selenium/issues/detail?id=214

.Clear should not trigger onchange event. I belive that if just sendkeys
would trigger events it would do the trick.

I have login page and when I want to login as different user and
call .Clear it triggers validation that username is not defined and
SendKeys do not trigger the validation again. I have made an workaround
that unless you want to empty textbox keeps always at least 1 character
within textbox but it is not clear solution.

sele...@googlecode.com

unread,
Nov 22, 2011, 9:44:21 AM11/22/11
to selenium-deve...@googlegroups.com

Comment #9 on issue 214 by milan.vo...@gmail.com: onchange js event fired
in WebElement.clear() and WebElement.sendKeys()
http://code.google.com/p/selenium/issues/detail?id=214

I have tries this with Selenium 2.12 (.Net) and Firefox 7.01 and IE 9 same
issues with both browser

sele...@googlecode.com

unread,
Jan 27, 2012, 6:10:00 AM1/27/12
to selenium-deve...@googlegroups.com

Comment #10 on issue 214 by glaurung...@gmail.com: onchange js event fired
in WebElement.clear() and WebElement.sendKeys()
http://code.google.com/p/selenium/issues/detail?id=214

Using version 2.17.0 and still HtmlUnit driver trigger onChange for
element.clear() but not for element.sendKeys(Keys.TAB)...

sele...@googlecode.com

unread,
Feb 1, 2012, 4:50:40 AM2/1/12
to selenium-develope...@googlegroups.com

Comment #11 on issue 214 by richard....@ca.com: onchange js event fired in
WebElement.clear() and WebElement.sendKeys()
http://code.google.com/p/selenium/issues/detail?id=214

I'm also hitting this issue with 2.18.0 IE8, FF9 & Chrome16 drivers - a
real pain.

sele...@googlecode.com

unread,
Feb 9, 2012, 10:09:16 AM2/9/12
to selenium-develope...@googlegroups.com

Comment #12 on issue 214 by jens.ran...@gmail.com: onchange js event fired
in WebElement.clear() and WebElement.sendKeys()
http://code.google.com/p/selenium/issues/detail?id=214

With Firefox 5.0.1 and Selenium 2.16.1 is not triggering onchange event for
me with I call element.clear() on an input element. Now you know!

sele...@googlecode.com

unread,
May 25, 2012, 5:21:11 AM5/25/12
to selenium-develope...@googlegroups.com

Comment #13 on issue 214 by Andrzej....@gmail.com: onchange js event fired
in WebElement.clear() and WebElement.sendKeys()
http://code.google.com/p/selenium/issues/detail?id=214

I'm still experiencing that WebElement.Clear() fires onchange()
WebDriver 2.21.0.0
Chrome 19.0.1084.46 m
Firefox 12.0

Will this ever be solved?

As a workaround in C# I've made extension method

public static class WebElementExtensions
{
public static void ClearWithBackspace(this IWebElement element)
{
int length = element.GetAttribute("value").Length;
element.Click();
element.SendKeys(Keys.End);
StringBuilder sb = new StringBuilder();
int i = 0;
while(i < length)
{
sb.Append(Keys.Backspace);
++i;
};
element.SendKeys(sb.ToString());
}
}

sele...@googlecode.com

unread,
Jun 18, 2012, 4:04:43 PM6/18/12
to selenium-develope...@googlegroups.com

Comment #14 on issue 214 by qode.qr...@gmail.com: onchange js event fired
in WebElement.clear() and WebElement.sendKeys()
http://code.google.com/p/selenium/issues/detail?id=214

web driver 2.23.1 with firefox 12.0. neither clear(), nor sendKeys()
trigger an onchange event. Also click() on another input/element after
sending keys to an input text box does NOT trigger an onchange event.

In summary with web driver 2.23.1 and firefox 12 there does not appear to
be any way to trigger an onchange event from a text input element.

sele...@googlecode.com

unread,
Jun 19, 2012, 7:35:10 PM6/19/12
to selenium-develope...@googlegroups.com
Updates:
Status: WorkingAsIntended

Comment #15 on issue 214 by jmle...@gmail.com: onchange js event fired in
WebElement.clear() and WebElement.sendKeys()
http://code.google.com/p/selenium/issues/detail?id=214

Closing this as working as intended.

If you use sendKeys() on an element, that element will still have focus
when the command is finished, so the change event will not fire. You must
change focus to another element for the change event to fire.

Please do not respond to this bug if you do not get the change event after
focusing on another element - that is a separate issue and you should file
a separate bug report.

sele...@googlecode.com

unread,
Sep 24, 2014, 8:53:23 AM9/24/14
to selenium-develope...@googlegroups.com

Comment #16 on issue 214 by seble...@gmail.com: onchange js event fired in
WebElement.clear() and WebElement.sendKeys()
https://code.google.com/p/selenium/issues/detail?id=214

This problem seems to have (partially) returned.

With WebDriver 2.43.1, calling WebElement.clear() trigger an onchange event
(tested on Firefox 32 and Chrome 37 on Windows 7).
WebElement.sendKeys() does *not* trigger onchange.

Abbreviated test case:

*HTML*

<form>
Input: <input name="bla" type="text" size="10"
onchange="this.value=this.value+'X'; console.log('onchange');" />
</form>

*Test*

public void testOnchange() throws Exception {
driver.get(baseUrl.toString());
Thread.sleep(5000);
WebElement input = driver.findElement(By.tagName("input"));
input.sendKeys("abc");
Thread.sleep(2000);
input.clear();
Thread.sleep(2000);
assertEquals("", input.getAttribute("value"));
}

Observed result:
First, the text "abc" appears in the field, then the field changes to
just "X". Thus the test fails.

Expected result:
The field should be empty at the end (because nothing triggers an onchange
event).


--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

sele...@googlecode.com

unread,
Oct 29, 2014, 9:12:27 PM10/29/14
to selenium-develope...@googlegroups.com

Comment #17 on issue 214 by Predato...@gmail.com: onchange js event fired
in WebElement.clear() and WebElement.sendKeys()
https://code.google.com/p/selenium/issues/detail?id=214

I'm experiencing this issue as well (selenium-java v 2.43.1).

Application has input field:
<input id="search" type="search" placeholder="Enter URL or IP Address"
data-bind="event: {change: $root.searchQuery}" class="input2"
maxlength="254s">

The field has a value of "test.com".

If I use field.clear(), an onchange event is kicked off and the page
refreshes without any change of focus.

Here is the method on my pageObject:
@FindBy(id = "search")
WebElement searchField;

@FindBy(id = "submit2")
WebElement urlSubmit;

public <T extends BasePage> T urlLookup(String url) throws
UnexpectedPageException {
searchField.clear(); //Causes page refresh and invalidates
elements.
searchField.sendKeys(url);
return clickUrlSubmit();
Reply all
Reply to author
Forward
0 new messages