From a75f3fd09b8683397b25efa72ea21bd7ffeb7053 Mon Sep 17 00:00:00 2001 From: Kenzie Raditya Tirtarahardja Date: Thu, 21 Aug 2025 03:10:07 +0800 Subject: [PATCH] script(webdriver): Element send keys append to the end of `filelist` if Multiple (#38407) Step 8.6 of [Element Send Keys](https://w3c.github.io/webdriver/#dfn-element-send-keys) remote end's implementation. > 6. Complete implementation specific steps equivalent to setting the [selected files](https://w3c.github.io/webdriver/#dfn-selected-files) on the [input](https://w3c.github.io/webdriver/#dfn-input) element. **If multiple is true files are be appended to element's [selected files](https://w3c.github.io/webdriver/#dfn-selected-files).** Testing: `webdriver/tests/classic/element_send_keys/file_upload.py` Fixes: https://github.com/servo/servo/issues/38190 --------- Signed-off-by: PotatoCP Co-authored-by: Euclid Ye --- components/script/dom/htmlinputelement.rs | 16 ++++++++++++++++ .../classic/element_send_keys/file_upload.py.ini | 6 ------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 6ffcd5ad088..cf68b60c90c 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -31,6 +31,7 @@ use net_traits::filemanager_thread::{FileManagerResult, FileManagerThreadMsg}; use net_traits::{CoreResourceMsg, IpcSend}; use script_bindings::codegen::GenericBindings::CharacterDataBinding::CharacterDataMethods; use script_bindings::codegen::GenericBindings::DocumentBinding::DocumentMethods; +use servo_config::pref; use style::attr::AttrValue; use style::selector_parser::PseudoElement; use style::str::{split_commas, str_join}; @@ -2293,6 +2294,21 @@ impl HTMLInputElement { let target = self.upcast::(); if self.Multiple() { + // When using WebDriver command element send keys, + // we are expected to append the files to the existing filelist. + if pref!(dom_testing_html_input_element_select_files_enabled) { + let filelist = self.filelist.get(); + if let Some(filelist) = filelist { + for i in 0..filelist.Length() { + files.push( + filelist + .Item(i) + .expect("We should have iterate within filelist length"), + ); + } + } + } + let opt_test_paths = opt_test_paths.map(|paths| { paths .iter() diff --git a/tests/wpt/meta/webdriver/tests/classic/element_send_keys/file_upload.py.ini b/tests/wpt/meta/webdriver/tests/classic/element_send_keys/file_upload.py.ini index 828ec3d761b..99bfd8703d1 100644 --- a/tests/wpt/meta/webdriver/tests/classic/element_send_keys/file_upload.py.ini +++ b/tests/wpt/meta/webdriver/tests/classic/element_send_keys/file_upload.py.ini @@ -1,10 +1,4 @@ [file_upload.py] - [test_multiple_files_send_twice] - expected: FAIL - - [test_single_file_appends_with_multiple_attribute] - expected: FAIL - [test_strict_hidden] expected: FAIL