mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 03:37:35 +00:00
Browser+WebContent+WebDriver: Move Get Element Attribute to WebContent
In doing so, this also implements a FIXME to handle boolean attributes.
This commit is contained in:
parent
7b1f3b7253
commit
1bc94e135f
16 changed files with 37 additions and 67 deletions
|
@ -495,15 +495,6 @@ void ConnectionFromClient::scroll_element_into_view(i32 element_id)
|
|||
element->scroll_into_view(options);
|
||||
}
|
||||
|
||||
Messages::WebContentServer::GetElementAttributeResponse ConnectionFromClient::get_element_attribute(i32 element_id, String const& name)
|
||||
{
|
||||
auto element = find_element_by_id(element_id);
|
||||
if (!element.has_value())
|
||||
return Optional<String> {};
|
||||
|
||||
return { element->get_attribute(name) };
|
||||
}
|
||||
|
||||
Messages::WebContentServer::GetElementPropertyResponse ConnectionFromClient::get_element_property(i32 element_id, String const& name)
|
||||
{
|
||||
auto element = find_element_by_id(element_id);
|
||||
|
|
|
@ -84,7 +84,6 @@ private:
|
|||
virtual void js_console_request_messages(i32) override;
|
||||
|
||||
virtual void scroll_element_into_view(i32 element_id) override;
|
||||
virtual Messages::WebContentServer::GetElementAttributeResponse get_element_attribute(i32 element_id, String const& name) override;
|
||||
virtual Messages::WebContentServer::GetElementPropertyResponse get_element_property(i32 element_id, String const& name) override;
|
||||
virtual Messages::WebContentServer::GetActiveDocumentsTypeResponse get_active_documents_type() override;
|
||||
virtual Messages::WebContentServer::GetComputedValueForElementResponse get_computed_value_for_element(i32 element_id, String const& property_name) override;
|
||||
|
|
|
@ -43,7 +43,6 @@ endpoint WebContentServer
|
|||
js_console_request_messages(i32 start_index) =|
|
||||
|
||||
scroll_element_into_view(i32 element_id) => ()
|
||||
get_element_attribute(i32 element_id, String name) => (Optional<String> attribute)
|
||||
get_element_property(i32 element_id, String name) => (Optional<String> property)
|
||||
get_active_documents_type() => (String type)
|
||||
get_computed_value_for_element(i32 element_id, String property_name) => (String computed_value)
|
||||
|
|
|
@ -14,4 +14,5 @@ endpoint WebDriverClient {
|
|||
find_element_from_element(JsonValue payload, String element_id) => (Web::WebDriver::Response response)
|
||||
find_elements_from_element(JsonValue payload, String element_id) => (Web::WebDriver::Response response)
|
||||
is_element_selected(String element_id) => (Web::WebDriver::Response response)
|
||||
get_element_attribute(String element_id, String name) => (Web::WebDriver::Response response)
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <AK/Vector.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/HTML/AttributeNames.h>
|
||||
#include <LibWeb/HTML/BrowsingContext.h>
|
||||
#include <LibWeb/HTML/HTMLInputElement.h>
|
||||
#include <LibWeb/HTML/HTMLOptionElement.h>
|
||||
|
@ -491,6 +492,38 @@ Messages::WebDriverClient::IsElementSelectedResponse WebDriverConnection::is_ele
|
|||
return make_success_response(selected);
|
||||
}
|
||||
|
||||
// 12.4.2 Get Element Attribute, https://w3c.github.io/webdriver/#dfn-get-element-attribute
|
||||
Messages::WebDriverClient::GetElementAttributeResponse WebDriverConnection::get_element_attribute(String const& element_id, String const& name)
|
||||
{
|
||||
// 1. If the current browsing context is no longer open, return error with error code no such window.
|
||||
TRY(ensure_open_top_level_browsing_context());
|
||||
|
||||
// FIXME: 2. Handle any user prompts and return its value if it is an error.
|
||||
|
||||
// 3. Let element be the result of trying to get a known connected element with url variable element id.
|
||||
auto* element = TRY(get_known_connected_element(element_id));
|
||||
|
||||
// 4. Let result be the result of the first matching condition:
|
||||
Optional<String> result;
|
||||
|
||||
// -> If name is a boolean attribute
|
||||
if (Web::HTML::is_boolean_attribute(name)) {
|
||||
// "true" (string) if the element has the attribute, otherwise null.
|
||||
if (element->has_attribute(name))
|
||||
result = "true"sv;
|
||||
}
|
||||
// -> Otherwise
|
||||
else {
|
||||
// The result of getting an attribute by name name.
|
||||
result = element->get_attribute(name);
|
||||
}
|
||||
|
||||
// 5. Return success with data result.
|
||||
if (result.has_value())
|
||||
return make_success_response(result.release_value());
|
||||
return make_success_response({});
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-no-longer-open
|
||||
ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_open_top_level_browsing_context()
|
||||
{
|
||||
|
|
|
@ -44,6 +44,7 @@ private:
|
|||
virtual Messages::WebDriverClient::FindElementFromElementResponse find_element_from_element(JsonValue const& payload, String const& element_id) override;
|
||||
virtual Messages::WebDriverClient::FindElementsFromElementResponse find_elements_from_element(JsonValue const& payload, String const& element_id) override;
|
||||
virtual Messages::WebDriverClient::IsElementSelectedResponse is_element_selected(String const& element_id) override;
|
||||
virtual Messages::WebDriverClient::GetElementAttributeResponse get_element_attribute(String const& element_id, String const& name) override;
|
||||
|
||||
ErrorOr<void, Web::WebDriver::Error> ensure_open_top_level_browsing_context();
|
||||
void restore_the_window();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue