From 8857c921f270e515f4d39e0b22c00be45b8bf668 Mon Sep 17 00:00:00 2001 From: James Graham Date: Fri, 23 Sep 2022 19:23:07 -0700 Subject: [PATCH] Fix setting cursor position in send keys I believe the expected behaviour is: * If the target already has focus, do nothing * Otherwise, if the target is focusable, set the selection to the last editable point in the element. Previously the spec was unconditionally focusing the target element (execpting some cases with file uploads), and therefore the letter of the spec was to never move the caret. This change updates it to only focus the target if it's not already the active element, and then move the caret to the end. --- index.html | 52 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index 7c90f08d..daea437a 100644 --- a/index.html +++ b/index.html @@ -6220,9 +6220,6 @@

Element Send Keys

  • If element is not keyboard-interactable, return error with error code element not interactable. - -

  • If element is not the active element run - the focusing steps for the element.

  • Run the substeps of the first matching condition: @@ -6230,6 +6227,10 @@

    Element Send Keys

    file is true
      +
    1. If the current session’s strict file interactability is true, + and element is not the active element run the focusing + steps for element. +

    2. Let files be the result of splitting text on the newline (\n) character. @@ -6275,6 +6276,9 @@

      Element Send Keys

      an error with error code element not interactable. +
    3. If element is not the active element run the + focusing steps for element. +

    4. Set a property value to text on element. @@ -6287,18 +6291,37 @@

      Element Send Keys

    element is content editable -
    If element does not currently have focus, - set the text insertion caret after any child content. +
    +
      +
    1. If element is not the active element: +

        +
      1. Run the focusing steps for element. + +

      2. Let child count be the [=map/size=] + of element's [=tree/children=]. + +

      3. Let range be a live range with [=range/start=] + and [=range/end=] (element, child count). + +

      4. Set the active document's selection + to range. +

      +
    +
    Otherwise
      -
    1. If element does not currently have focus, - let current text length be the - [=string/length=] of element’s API value. +

    2. If element is not the active element: +

        +
      1. Let current text length be the + [=string/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. +

      3. Run the focusing steps for element. + +

      4. Set the text insertion caret using set selection range + using current text length for both the start + and end parameters. +

    @@ -11156,6 +11179,13 @@

    Index

  • Visibility state visible +

    The following attributes are defined + in the Selection API specification: [[SELECTION-API]] +

    + +
    Selenium
    The following functions are defined within the Selenium project, at