1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 17:47:36 +00:00

LibWeb+WebContent+WebDriver: Implement Get Active Element

Unfortunately, nothing ever calls DOM::Document::set_active_element at
the moment, so this will always return ErrorCode::NoSuchElement.
This commit is contained in:
Timothy Flynn 2022-11-14 19:02:23 -05:00 committed by Linus Groh
parent 269a931414
commit cb91e6067c
7 changed files with 33 additions and 0 deletions

View file

@ -23,6 +23,7 @@ endpoint WebDriverClient {
find_elements(JsonValue payload) => (Web::WebDriver::Response response)
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)
get_active_element() => (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)
get_element_property(String element_id, String name) => (Web::WebDriver::Response response)

View file

@ -705,6 +705,25 @@ Messages::WebDriverClient::FindElementsFromElementResponse WebDriverConnection::
return TRY(find(*start_node, *location_strategy, selector));
}
// 12.3.8 Get Active Element, https://w3c.github.io/webdriver/#get-active-element
Messages::WebDriverClient::GetActiveElementResponse WebDriverConnection::get_active_element()
{
// 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 active element be the active element of the current browsing contexts document element.
auto* active_element = m_page_host.page().top_level_browsing_context().active_document()->active_element();
// 4. If active element is a non-null element, return success with data set to web element reference object for active element.
// Otherwise, return error with error code no such element.
if (active_element)
return String::number(active_element->id());
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchElement, "The current document does not have an active element"sv);
}
// 12.4.1 Is Element Selected, https://w3c.github.io/webdriver/#dfn-is-element-selected
Messages::WebDriverClient::IsElementSelectedResponse WebDriverConnection::is_element_selected(String const& element_id)
{

View file

@ -58,6 +58,7 @@ private:
virtual Messages::WebDriverClient::FindElementsResponse find_elements(JsonValue const& payload) override;
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::GetActiveElementResponse get_active_element() 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;
virtual Messages::WebDriverClient::GetElementPropertyResponse get_element_property(String const& element_id, String const& name) override;