[WebDriver] Implement XPath Locator Strategy (#37783)

1. Implement XPath Locator Strategy
2. Use it for "Find Element(s)", "Find Element(s) from Element", "Find
Element(s) from Shadow Root"

Testing: `tests\wpt\tests\webdriver\tests\classic\find_element*\find.py`

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
Euclid Ye 2025-07-01 01:20:52 +08:00 committed by GitHub
parent f682f9d6f5
commit d781d1b1cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 190 additions and 51 deletions

View file

@ -1172,11 +1172,12 @@ impl Handler {
WebDriverScriptCommand::FindElementsTagName(parameters.value.clone(), sender);
self.browsing_context_script_command::<true>(cmd)?;
},
_ => {
return Err(WebDriverError::new(
ErrorStatus::UnsupportedOperation,
"Unsupported locator strategy",
));
LocatorStrategy::XPath => {
let cmd = WebDriverScriptCommand::FindElementsXpathSelector(
parameters.value.clone(),
sender,
);
self.browsing_context_script_command::<true>(cmd)?;
},
}
@ -1242,11 +1243,13 @@ impl Handler {
);
self.browsing_context_script_command::<true>(cmd)?;
},
_ => {
return Err(WebDriverError::new(
ErrorStatus::UnsupportedOperation,
"Unsupported locator strategy",
));
LocatorStrategy::XPath => {
let cmd = WebDriverScriptCommand::FindElementElementsXPathSelector(
parameters.value.clone(),
element.to_string(),
sender,
);
self.browsing_context_script_command::<true>(cmd)?;
},
}
@ -1302,11 +1305,13 @@ impl Handler {
);
self.browsing_context_script_command::<true>(cmd)?;
},
_ => {
return Err(WebDriverError::new(
ErrorStatus::UnsupportedOperation,
"Unsupported locator strategy",
));
LocatorStrategy::XPath => {
let cmd = WebDriverScriptCommand::FindShadowElementsXPathSelector(
parameters.value.clone(),
shadow_root.to_string(),
sender,
);
self.browsing_context_script_command::<true>(cmd)?;
},
}