Open Bug 1550680 Opened 5 years ago Updated 1 month ago

"WebDriver:ElementClick" for <option> fires "change" and "input" events even without any changes made

Categories

(Remote Protocol :: Marionette, defect, P3)

66 Branch
defect

Tracking

(Not tracked)

People

(Reporter: alt.mholle, Unassigned)

References

(Depends on 1 open bug, Blocks 1 open bug)

Details

Attachments

(2 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0

Steps to reproduce:

Given the following html:

<!DOCTYPE html>
<html lang="en">
<head><title>Onchange issue</title></head>
<body>
<script> var counter = 0; </script>
<select name="dd" onchange="++counter">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
</body>
</html>

When running the following Selenium commands:

driver = webdriver.Firefox()
driver.get(url)

aPath = "//select[@name='dd']/option[text()='A']"
bPath = "//select[@name='dd']/option[text()='B']"
cPath = "//select[@name='dd']/option[text()='C']"

driver.find_element_by_xpath(bPath).click()
driver.find_element_by_xpath(cPath).click()
driver.find_element_by_xpath(cPath).click()

print('Fired onchange ' + str(driver.execute_script('return counter;')) + ' times!')

Actual results:

The onchange event is triggered 3 times, meaning it fires when the value does not change.

Expected results:

When using other drivers (such as chromedriver) or manually selecting the options in Firefox, the onchange event is triggered 2 times, as it should.

Thank you for filing this bug. It's indeed an oversight and specifically a missing check if the target element is different from the currently selected element:

https://searchfox.org/mozilla-central/rev/b9da45f63cb567244933c77b2c7e827a057d3f9b/testing/marionette/interaction.js#284-285

Blocks: webdriver
Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3
Summary: onchange is fired in select even if the value does not change → "WebDriver:ElementClick" for <option> fires "change" and "input" events even without any changes made
Severity: normal → S3
Product: Testing → Remote Protocol

Fixed unexpected change and input events being fired when clicking an
already selected <option> as they should only be fired when the value
changes.

Assignee: nobody → oj
Status: NEW → ASSIGNED

Oliver, would you have a chance to check my review comments which require an update of the patch? Thanks.

Flags: needinfo?(omedhurst)

Apologies, I don't have the time to work on these patches for now.

Flags: needinfo?(omedhurst)

The bug assignee is inactive on Bugzilla, so the assignee is being reset.

Assignee: omedhurst → nobody
Status: ASSIGNED → NEW
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: