script(webdriver): Send keys set caret at the end of content of text input (#38250)

Remote end step of [element send
keys](https://w3c.github.io/webdriver/#element-send-keys)

> Step 8.2. Set the text insertion caret using [set selection
range](https://w3c.github.io/webdriver/#dfn-set-selection-range) using
current text length for both the start and end parameters.

Also check if the element is already an active element before focusing
(Step 7.7).

Testing:
`./tests/wpt/tests/webdriver/tests/classic/element_send_keys/form_controls.py`

---------

Signed-off-by: PotatoCP <Kenzie.Raditya.Tirtarahardja@huawei.com>
Signed-off-by: Kenzie Raditya Tirtarahardja <kenzieradityatirtarahardja18@gmail.com>
Co-authored-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
Kenzie Raditya Tirtarahardja 2025-07-25 15:24:48 +08:00 committed by GitHub
parent ab78a76da6
commit 165ede59cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 47 additions and 23 deletions

View file

@ -1733,8 +1733,17 @@ impl Element {
/// <https://dom.spec.whatwg.org/#document-element>
pub(crate) fn is_document_element(&self) -> bool {
if let Some(ref document_element) = self.owner_document().GetDocumentElement() {
**document_element == *self
if let Some(document_element) = self.owner_document().GetDocumentElement() {
*document_element == *self
} else {
false
}
}
/// <https://html.spec.whatwg.org/multipage/#dom-document-activeelement>
pub(crate) fn is_active_element(&self) -> bool {
if let Some(active_element) = self.owner_document().GetActiveElement() {
*active_element == *self
} else {
false
}