1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:47:35 +00:00

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.
This commit is contained in:
Timothy Flynn 2022-11-10 09:29:10 -05:00 committed by Linus Groh
parent 941bc47538
commit 7b1f3b7253

View file

@ -12,6 +12,7 @@
#include <AK/JsonValue.h>
#include <AK/Vector.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/HTMLInputElement.h>
#include <LibWeb/HTML/HTMLOptionElement.h>
@ -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<Web::DOM::ParentNode*, Web::WebDriver::Error> get_known_connected_element(StringView element_id)
static 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.
@ -93,12 +94,10 @@ static ErrorOr<Web::DOM::ParentNode*, Web::WebDriver::Error> 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<Web::DOM::ParentNode>(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<Web::DOM::ParentNode*>(node);
return static_cast<Web::DOM::Element*>(node);
}
static ErrorOr<String, Web::WebDriver::Error> get_property(JsonValue const& payload, StringView key)