From 7b1f3b72532f231c85ac16910dd0b3bea372e71b Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 10 Nov 2022 09:29:10 -0500 Subject: [PATCH] WebContent: Return a DOM::Element when getting a known connected element This is how WebContent::ConnectionFromClient also behaves. Returning the element as a DOM::ParentNode isn't quite strict enough for upcoming endpoints. --- Userland/Services/WebContent/WebDriverConnection.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index 3600ab0409..73a2d7e49c 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -83,7 +84,7 @@ static JsonObject web_element_reference_object(Web::DOM::Node const& element) } // https://w3c.github.io/webdriver/#dfn-get-a-known-connected-element -static ErrorOr get_known_connected_element(StringView element_id) +static ErrorOr 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. @@ -93,12 +94,10 @@ static ErrorOr get_known_connected auto* node = Web::DOM::Node::from_id(*element); - if (!node) + if (!node || !node->is_element()) return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchElement, String::formatted("Could not find element with ID: {}", element_id)); - if (!is(node)) - return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchElement, String::formatted("Element with ID is not a parent node: {}", element_id)); - return static_cast(node); + return static_cast(node); } static ErrorOr get_property(JsonValue const& payload, StringView key)