mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Implement tag name selector for FindElements WebDriver command
This commit is contained in:
parent
7d5b324bda
commit
dec73e4cea
5 changed files with 47 additions and 14 deletions
|
@ -2035,6 +2035,14 @@ impl ScriptThread {
|
||||||
reply,
|
reply,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
WebDriverScriptCommand::FindElementsTagName(selector, reply) => {
|
||||||
|
webdriver_handlers::handle_find_elements_tag_name(
|
||||||
|
&*documents,
|
||||||
|
pipeline_id,
|
||||||
|
selector,
|
||||||
|
reply,
|
||||||
|
)
|
||||||
|
},
|
||||||
WebDriverScriptCommand::FindElementElementCSS(selector, element_id, reply) => {
|
WebDriverScriptCommand::FindElementElementCSS(selector, element_id, reply) => {
|
||||||
webdriver_handlers::handle_find_element_element_css(
|
webdriver_handlers::handle_find_element_element_css(
|
||||||
&*documents,
|
&*documents,
|
||||||
|
|
|
@ -223,6 +223,25 @@ pub fn handle_find_elements_css(
|
||||||
reply.send(node_ids).unwrap();
|
reply.send(node_ids).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn handle_find_elements_tag_name(
|
||||||
|
documents: &Documents,
|
||||||
|
pipeline: PipelineId,
|
||||||
|
selector: String,
|
||||||
|
reply: IpcSender<Result<Vec<String>, ()>>,
|
||||||
|
) {
|
||||||
|
let node_ids = documents
|
||||||
|
.find_document(pipeline)
|
||||||
|
.ok_or(())
|
||||||
|
.and_then(|doc| Ok(doc.GetElementsByTagName(DOMString::from(selector))))
|
||||||
|
.map(|nodes| {
|
||||||
|
nodes
|
||||||
|
.elements_iter()
|
||||||
|
.map(|x| x.upcast::<Node>().unique_id())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
});
|
||||||
|
reply.send(node_ids).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn handle_find_element_element_css(
|
pub fn handle_find_element_element_css(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
|
|
|
@ -27,6 +27,7 @@ pub enum WebDriverScriptCommand {
|
||||||
FindElementCSS(String, IpcSender<Result<Option<String>, ()>>),
|
FindElementCSS(String, IpcSender<Result<Option<String>, ()>>),
|
||||||
FindElementTagName(String, IpcSender<Result<Option<String>, ()>>),
|
FindElementTagName(String, IpcSender<Result<Option<String>, ()>>),
|
||||||
FindElementsCSS(String, IpcSender<Result<Vec<String>, ()>>),
|
FindElementsCSS(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>, ()>>),
|
||||||
FindElementElementsCSS(String, String, IpcSender<Result<Option<String>, ()>>),
|
FindElementElementsCSS(String, String, IpcSender<Result<Option<String>, ()>>),
|
||||||
FocusElement(String, IpcSender<Result<(), ()>>),
|
FocusElement(String, IpcSender<Result<(), ()>>),
|
||||||
|
|
|
@ -902,20 +902,31 @@ impl Handler {
|
||||||
Ok(WebDriverResponse::Void)
|
Ok(WebDriverResponse::Void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/webdriver/#find-elements
|
||||||
fn handle_find_elements(
|
fn handle_find_elements(
|
||||||
&self,
|
&self,
|
||||||
parameters: &LocatorParameters,
|
parameters: &LocatorParameters,
|
||||||
) -> WebDriverResult<WebDriverResponse> {
|
) -> WebDriverResult<WebDriverResponse> {
|
||||||
if parameters.using != LocatorStrategy::CSSSelector {
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
return Err(WebDriverError::new(
|
|
||||||
ErrorStatus::UnsupportedOperation,
|
match parameters.using {
|
||||||
"Unsupported locator strategy",
|
LocatorStrategy::CSSSelector => {
|
||||||
));
|
let cmd = WebDriverScriptCommand::FindElementsCSS(parameters.value.clone(), sender);
|
||||||
|
self.browsing_context_script_command(cmd)?;
|
||||||
|
},
|
||||||
|
LocatorStrategy::TagName => {
|
||||||
|
let cmd =
|
||||||
|
WebDriverScriptCommand::FindElementsTagName(parameters.value.clone(), sender);
|
||||||
|
self.browsing_context_script_command(cmd)?;
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
return Err(WebDriverError::new(
|
||||||
|
ErrorStatus::UnsupportedOperation,
|
||||||
|
"Unsupported locator strategy",
|
||||||
|
));
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
|
||||||
let cmd = WebDriverScriptCommand::FindElementsCSS(parameters.value.clone(), sender);
|
|
||||||
self.browsing_context_script_command(cmd)?;
|
|
||||||
match receiver.recv().unwrap() {
|
match receiver.recv().unwrap() {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
let resp_value: Vec<Value> = value
|
let resp_value: Vec<Value> = value
|
||||||
|
|
|
@ -5,9 +5,6 @@
|
||||||
[test_find_elements_link_text[<a href=#>LINK TEXT</a>-LINK TEXT\]]
|
[test_find_elements_link_text[<a href=#>LINK TEXT</a>-LINK TEXT\]]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[test_htmldocument[tag name-html\]]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[test_find_elements_link_text[<a href=#>link text</a>-link text\]]
|
[test_find_elements_link_text[<a href=#>link text</a>-link text\]]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -50,9 +47,6 @@
|
||||||
[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