mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Implement tag name selector for FindElementsFromElement WebDriver command
This commit is contained in:
parent
616a81fb27
commit
bf6ea64e8c
5 changed files with 65 additions and 27 deletions
|
@ -2070,6 +2070,15 @@ impl ScriptThread {
|
||||||
reply,
|
reply,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
WebDriverScriptCommand::FindElementElementsTagName(selector, element_id, reply) => {
|
||||||
|
webdriver_handlers::handle_find_element_elements_tag_name(
|
||||||
|
&*documents,
|
||||||
|
pipeline_id,
|
||||||
|
element_id,
|
||||||
|
selector,
|
||||||
|
reply,
|
||||||
|
)
|
||||||
|
},
|
||||||
WebDriverScriptCommand::FocusElement(element_id, reply) => {
|
WebDriverScriptCommand::FocusElement(element_id, reply) => {
|
||||||
webdriver_handlers::handle_focus_element(
|
webdriver_handlers::handle_focus_element(
|
||||||
&*documents,
|
&*documents,
|
||||||
|
|
|
@ -284,7 +284,7 @@ pub fn handle_find_element_elements_css(
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
element_id: String,
|
element_id: String,
|
||||||
selector: String,
|
selector: String,
|
||||||
reply: IpcSender<Result<Option<String>, ()>>,
|
reply: IpcSender<Result<Vec<String>, ()>>,
|
||||||
) {
|
) {
|
||||||
let node_ids = find_node_by_unique_id(documents, pipeline, element_id)
|
let node_ids = find_node_by_unique_id(documents, pipeline, element_id)
|
||||||
.ok_or(())
|
.ok_or(())
|
||||||
|
@ -295,12 +295,34 @@ pub fn handle_find_element_elements_css(
|
||||||
.map(|nodes| {
|
.map(|nodes| {
|
||||||
nodes
|
nodes
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| Some(x.upcast::<Node>().unique_id()))
|
.map(|x| x.upcast::<Node>().unique_id())
|
||||||
.collect()
|
.collect()
|
||||||
});
|
});
|
||||||
reply.send(node_ids).unwrap();
|
reply.send(node_ids).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn handle_find_element_elements_tag_name(
|
||||||
|
documents: &Documents,
|
||||||
|
pipeline: PipelineId,
|
||||||
|
element_id: String,
|
||||||
|
selector: String,
|
||||||
|
reply: IpcSender<Result<Vec<String>, ()>>,
|
||||||
|
) {
|
||||||
|
let node_ids = find_node_by_unique_id(documents, pipeline, element_id)
|
||||||
|
.ok_or(())
|
||||||
|
.and_then(|node| match node.downcast::<Element>() {
|
||||||
|
Some(elem) => Ok(elem.GetElementsByTagName(DOMString::from(selector))),
|
||||||
|
None => Err(()),
|
||||||
|
})
|
||||||
|
.map(|nodes| {
|
||||||
|
nodes
|
||||||
|
.elements_iter()
|
||||||
|
.map(|x| x.upcast::<Node>().unique_id())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
});
|
||||||
|
reply.send(node_ids).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn handle_focus_element(
|
pub fn handle_focus_element(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
|
|
|
@ -30,7 +30,8 @@ pub enum WebDriverScriptCommand {
|
||||||
FindElementsTagName(String, IpcSender<Result<Vec<String>, ()>>),
|
FindElementsTagName(String, IpcSender<Result<Vec<String>, ()>>),
|
||||||
FindElementElementCSS(String, String, IpcSender<Result<Option<String>, ()>>),
|
FindElementElementCSS(String, String, IpcSender<Result<Option<String>, ()>>),
|
||||||
FindElementElementTagName(String, String, IpcSender<Result<Option<String>, ()>>),
|
FindElementElementTagName(String, String, IpcSender<Result<Option<String>, ()>>),
|
||||||
FindElementElementsCSS(String, String, IpcSender<Result<Option<String>, ()>>),
|
FindElementElementsCSS(String, String, IpcSender<Result<Vec<String>, ()>>),
|
||||||
|
FindElementElementsTagName(String, String, IpcSender<Result<Vec<String>, ()>>),
|
||||||
FocusElement(String, IpcSender<Result<(), ()>>),
|
FocusElement(String, IpcSender<Result<(), ()>>),
|
||||||
GetActiveElement(IpcSender<Option<String>>),
|
GetActiveElement(IpcSender<Option<String>>),
|
||||||
GetCookie(String, IpcSender<Vec<Serde<Cookie<'static>>>>),
|
GetCookie(String, IpcSender<Vec<Serde<Cookie<'static>>>>),
|
||||||
|
|
|
@ -997,34 +997,46 @@ impl Handler {
|
||||||
element: &WebElement,
|
element: &WebElement,
|
||||||
parameters: &LocatorParameters,
|
parameters: &LocatorParameters,
|
||||||
) -> WebDriverResult<WebDriverResponse> {
|
) -> WebDriverResult<WebDriverResponse> {
|
||||||
if parameters.using != LocatorStrategy::CSSSelector {
|
|
||||||
return Err(WebDriverError::new(
|
|
||||||
ErrorStatus::UnsupportedOperation,
|
|
||||||
"Unsupported locator strategy",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
let cmd = WebDriverScriptCommand::FindElementElementsCSS(
|
|
||||||
parameters.value.clone(),
|
|
||||||
element.id.clone(),
|
|
||||||
sender,
|
|
||||||
);
|
|
||||||
|
|
||||||
self.browsing_context_script_command(cmd)?;
|
match parameters.using {
|
||||||
|
LocatorStrategy::CSSSelector => {
|
||||||
|
let cmd = WebDriverScriptCommand::FindElementElementsCSS(
|
||||||
|
parameters.value.clone(),
|
||||||
|
element.id.clone(),
|
||||||
|
sender,
|
||||||
|
);
|
||||||
|
self.browsing_context_script_command(cmd)?;
|
||||||
|
},
|
||||||
|
LocatorStrategy::TagName => {
|
||||||
|
let cmd = WebDriverScriptCommand::FindElementElementsTagName(
|
||||||
|
parameters.value.clone(),
|
||||||
|
element.id.clone(),
|
||||||
|
sender,
|
||||||
|
);
|
||||||
|
self.browsing_context_script_command(cmd)?;
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
return Err(WebDriverError::new(
|
||||||
|
ErrorStatus::UnsupportedOperation,
|
||||||
|
"Unsupported locator strategy",
|
||||||
|
));
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
match receiver.recv().unwrap() {
|
match receiver.recv().unwrap() {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
let value_resp = value
|
let resp_value: Vec<Value> = value
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| serde_json::to_value(WebElement::new(x)).unwrap())
|
.map(|x| serde_json::to_value(WebElement::new(x)).unwrap())
|
||||||
.collect::<Vec<Value>>();
|
.collect();
|
||||||
let value_resp = serde_json::Value::Array(value_resp);
|
Ok(WebDriverResponse::Generic(ValueResponse(
|
||||||
Ok(WebDriverResponse::Generic(ValueResponse(value_resp)))
|
serde_json::to_value(resp_value)?,
|
||||||
|
)))
|
||||||
},
|
},
|
||||||
Err(_) => Err(WebDriverError::new(
|
Err(_) => Err(WebDriverError::new(
|
||||||
ErrorStatus::InvalidSelector,
|
ErrorStatus::InvalidSelector,
|
||||||
"Invalid Selector",
|
"Invalid selector",
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,18 +44,12 @@
|
||||||
[test_parent_of_document_node_errors]
|
[test_parent_of_document_node_errors]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[test_no_element[css selector-#wontExist\]]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[test_find_elements_partial_link_text[<a href=#>partial link&text</a>-k&t\]]
|
[test_find_elements_partial_link_text[<a href=#>partial link&text</a>-k&t\]]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[test_find_elements[xpath-//a\]]
|
[test_find_elements[xpath-//a\]]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[test_find_elements[tag name-a\]]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[test_find_elements_partial_link_text[<a href=# style='text-transform: uppercase'>partial link text</a>-LINK\]]
|
[test_find_elements_partial_link_text[<a href=# style='text-transform: uppercase'>partial link text</a>-LINK\]]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue