Closed Bug 1791736 Opened 2 years ago Closed 2 years ago

WebDriver:ElementSendKeys should only set the caret if the element is not focused

Categories

(Remote Protocol :: Marionette, defect)

Default
defect

Tracking

(firefox107 fixed)

RESOLVED FIXED
107 Branch
Tracking Status
firefox107 --- fixed

People

(Reporter: jdescottes, Assigned: jgraham)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

From https://github.com/mozilla/geckodriver/issues/2015

The spec at https://www.w3.org/TR/webdriver/#element-send-keys says

Otherwise

  1. If element does not currently have focus, let current text length be the length of element’s API value.
  2. Set the text insertion caret using set selection range using current text length for both the start and end parameters.

I think we can only run step 2 (updating the caret position) if the element does not have focus, otherwise current text length is not set? Might need to clarify this first.

But if this is confirmed, marionette is currently unconditionally updating the selection range whenever sendKeys is used https://searchfox.org/mozilla-central/rev/b1e5f2c7c96be36974262551978d54f457db2cae/remote/marionette/interaction.js#634-635 and we should update it to only update the caret if the input is not focused.

James, what do you think about the WebDriver spec extract in the summary? Do you agree that step 2 should only be done if step 1 If element does not currently have focus was true? Is that a bug in the spec that should be clarified?

Flags: needinfo?(james)

OK, so I agree that the spec is wrong at the point you mentioned. But it's more fundamentally broken too: step 7 always focuses the element, so everything in step 8 that happens if the element doesn't have focus should never happen. So I think a strict reading of the current spec is that gecko's behaviour is correct and we should call focus() on the element, but never change the cursor position. I'm almost certain that's not what's intended.

I think the expected behaviour is basically:

  1. Check if the element has focus
  2. If not, give element the focus and set the cursor position to the end
Flags: needinfo?(james)

Only if the element isn't already focused. If it is already focused,
don't alter the focus.

Assignee: nobody → james
Status: NEW → ASSIGNED
Pushed by james@hoppipolla.co.uk: https://hg.mozilla.org/integration/autoland/rev/041c4a14b5ef Move the caret to the end for send_keys r=webdriver-reviewers,jdescottes,whimboo
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/36226 for changes under testing/web-platform/tests
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 107 Branch
Upstream PR merged by moz-wptsync-bot
Product: Testing → Remote Protocol
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: