1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:57:44 +00:00

WebDriver: Implement stub for .../element/{element id}/click

This patch adds a stub implementation for the POST
/session/{session id}/element/{element id}/click endpoint.
This commit is contained in:
Baitinq 2022-12-24 02:17:06 +01:00 committed by Andreas Kling
parent 6a72a4df96
commit 419dea0996
7 changed files with 58 additions and 0 deletions

View file

@ -1172,6 +1172,50 @@ Messages::WebDriverClient::IsElementEnabledResponse WebDriverConnection::is_elem
return enabled;
}
// 12.5.1 Element Click, https://w3c.github.io/webdriver/#element-click
Messages::WebDriverClient::ClickResponse WebDriverConnection::click(DeprecatedString const& element_id)
{
// 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());
// 2. Handle any user prompts and return its value if it is an error.
TRY(handle_any_user_prompts());
// 3. Let element be the result of trying to get a known element with element id.
auto* element = TRY(get_known_connected_element(element_id));
// 4. If the element is an input element in the file upload state return error with error code invalid argument.
if (is<Web::HTML::HTMLInputElement>(*element)) {
// -> The result of elements checkedness.
auto& input = static_cast<Web::HTML::HTMLInputElement&>(*element);
using enum Web::HTML::HTMLInputElement::TypeAttributeState;
if (input.type_state() == FileUpload)
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Clicking on an input element in the file upload state is not supported"sv);
}
// 5. Scroll into view the elements container.
auto scroll_or_error = scroll_element_into_view(*element);
// 6. If elements container is still not in view, return error with error code element not interactable.
if (scroll_or_error.is_error())
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::ElementNotInteractable, "Elements container is still not in view after scrolling"sv);
// FIXME: 7. If elements container is obscured by another element, return error with error code element click intercepted.
// 8. Matching on element:
// FIXME: option element
// FIXME: Otherwise
// FIXME: 9. Wait until the user agent event loop has spun enough times to process the DOM events generated by the previous step.
// FIXME: 10. Perform implementation-defined steps to allow any navigations triggered by the click to start.
// FIXME: 11. Try to wait for navigation to complete.
// FIXME: 12. Try to run the post-navigation checks.
// FIXME: 13. Return success with data null.
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Click not implemented"sv);
}
// 13.1 Get Page Source, https://w3c.github.io/webdriver/#dfn-get-page-source
Messages::WebDriverClient::GetSourceResponse WebDriverConnection::get_source()
{