Skip to content
Permalink
Browse files

Implement tag name selector for FindElements WebDriver command

  • Loading branch information...
georgeroman committed Jun 17, 2019
1 parent 7d5b324 commit dec73e4cea93d34736c925d4bd62e57b7d664f6b
@@ -2035,6 +2035,14 @@ impl ScriptThread {
reply,
)
},
WebDriverScriptCommand::FindElementsTagName(selector, reply) => {
webdriver_handlers::handle_find_elements_tag_name(
&*documents,
pipeline_id,
selector,
reply,
)
},
WebDriverScriptCommand::FindElementElementCSS(selector, element_id, reply) => {
webdriver_handlers::handle_find_element_element_css(
&*documents,
@@ -223,6 +223,25 @@ pub fn handle_find_elements_css(
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(
documents: &Documents,
pipeline: PipelineId,
@@ -27,6 +27,7 @@ pub enum WebDriverScriptCommand {
FindElementCSS(String, IpcSender<Result<Option<String>, ()>>),
FindElementTagName(String, IpcSender<Result<Option<String>, ()>>),
FindElementsCSS(String, IpcSender<Result<Vec<String>, ()>>),
FindElementsTagName(String, IpcSender<Result<Vec<String>, ()>>),
FindElementElementCSS(String, String, IpcSender<Result<Option<String>, ()>>),
FindElementElementsCSS(String, String, IpcSender<Result<Option<String>, ()>>),
FocusElement(String, IpcSender<Result<(), ()>>),
@@ -902,20 +902,31 @@ impl Handler {
Ok(WebDriverResponse::Void)
}

// https://w3c.github.io/webdriver/#find-elements
fn handle_find_elements(
&self,
parameters: &LocatorParameters,
) -> WebDriverResult<WebDriverResponse> {
if parameters.using != LocatorStrategy::CSSSelector {
return Err(WebDriverError::new(
ErrorStatus::UnsupportedOperation,
"Unsupported locator strategy",
));
let (sender, receiver) = ipc::channel().unwrap();

match parameters.using {
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() {
Ok(value) => {
let resp_value: Vec<Value> = value
@@ -5,9 +5,6 @@
[test_find_elements_link_text[<a href=#>LINK TEXT</a>-LINK TEXT\]]
expected: FAIL

[test_htmldocument[tag name-html\]]
expected: FAIL

[test_find_elements_link_text[<a href=#>link text</a>-link text\]]
expected: FAIL

@@ -50,9 +47,6 @@
[test_find_elements[xpath-//a\]]
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\]]
expected: FAIL

0 comments on commit dec73e4

Please sign in to comment.
You can’t perform that action at this time.