Closed Bug 1791736 Opened 1 year ago Closed 1 year ago

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


(Remote Protocol :: Marionette, defect)



(firefox107 fixed)

107 Branch
Tracking Status
firefox107 --- fixed


(Reporter: jdescottes, Assigned: jgraham)


(Blocks 1 open bug)



(1 file)


The spec at says


  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 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)
See Also: → 1789967

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

Assignee: nobody → james
Pushed by
Move the caret to the end for send_keys r=webdriver-reviewers,jdescottes,whimboo
Created web-platform-tests PR for changes under testing/web-platform/tests
Closed: 1 year 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.