mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 17:24:48 -05:00
LibWeb: Implement getting a known connected element closer to the spec
Namely, we must always return NoSuchError invalid element IDs, and we must handle stale elements.
This commit is contained in:
parent
264b2827cd
commit
92a37b3b1a
Notes:
github-actions[bot]
2024-09-29 09:49:34 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/92a37b3b1a6 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1557 Reviewed-by: https://github.com/AtkinsSJ
1 changed files with 13 additions and 3 deletions
|
@ -58,20 +58,30 @@ bool represents_a_web_element(JsonValue const& value)
|
|||
return value.as_object().has_string(web_element_identifier);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-get-a-known-connected-element
|
||||
// https://w3c.github.io/webdriver/#dfn-get-a-known-element
|
||||
ErrorOr<Web::DOM::Element*, Web::WebDriver::Error> get_known_connected_element(StringView element_id)
|
||||
{
|
||||
// NOTE: The whole concept of "connected elements" is not implemented yet. See get_or_create_a_web_element_reference().
|
||||
// For now the element is only represented by its ID.
|
||||
|
||||
// 1. If not node reference is known with session, session's current browsing context, and reference return error
|
||||
// with error code no such element.
|
||||
auto element = element_id.to_number<int>();
|
||||
if (!element.has_value())
|
||||
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Element ID is not an integer");
|
||||
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchElement, "Element ID is not an integer");
|
||||
|
||||
// 2. Let node be the result of get a node with session, session's current browsing context, and reference.
|
||||
auto* node = Web::DOM::Node::from_unique_id(*element);
|
||||
|
||||
if (!node || !node->is_element())
|
||||
// 3. If node is not null and node does not implement Element return error with error code no such element.
|
||||
if (node && !node->is_element())
|
||||
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchElement, ByteString::formatted("Could not find element with ID: {}", element_id));
|
||||
|
||||
// 4. If node is null or node is stale return error with error code stale element reference.
|
||||
if (!node || is_element_stale(*node))
|
||||
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::StaleElementReference, ByteString::formatted("Element with ID: {} is stale", element_id));
|
||||
|
||||
// 5. Return success with data node.
|
||||
return static_cast<Web::DOM::Element*>(node);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue