Skip to content
Permalink
Browse files

Implement tag name selector for FindElementsFromElement WebDriver com…

…mand
  • Loading branch information...
georgeroman committed Jun 17, 2019
1 parent 616a81f commit bf6ea64e8c2b12b57fbb755a81c2de3f3a3c3c83
@@ -2070,6 +2070,15 @@ impl ScriptThread {
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) => {
webdriver_handlers::handle_focus_element(
&*documents,
@@ -284,7 +284,7 @@ pub fn handle_find_element_elements_css(
pipeline: PipelineId,
element_id: 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)
.ok_or(())
@@ -295,12 +295,34 @@ pub fn handle_find_element_elements_css(
.map(|nodes| {
nodes
.iter()
.map(|x| Some(x.upcast::<Node>().unique_id()))
.map(|x| x.upcast::<Node>().unique_id())
.collect()
});
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(
documents: &Documents,
pipeline: PipelineId,
@@ -30,7 +30,8 @@ pub enum WebDriverScriptCommand {
FindElementsTagName(String, IpcSender<Result<Vec<String>, ()>>),
FindElementElementCSS(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<(), ()>>),
GetActiveElement(IpcSender<Option<String>>),
GetCookie(String, IpcSender<Vec<Serde<Cookie<'static>>>>),
@@ -997,34 +997,46 @@ impl Handler {
element: &WebElement,
parameters: &LocatorParameters,
) -> WebDriverResult<WebDriverResponse> {
if parameters.using != LocatorStrategy::CSSSelector {
return Err(WebDriverError::new(
ErrorStatus::UnsupportedOperation,
"Unsupported locator strategy",
));
}

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() {
Ok(value) => {
let value_resp = value
let resp_value: Vec<Value> = value
.into_iter()
.map(|x| serde_json::to_value(WebElement::new(x)).unwrap())
.collect::<Vec<Value>>();
let value_resp = serde_json::Value::Array(value_resp);
Ok(WebDriverResponse::Generic(ValueResponse(value_resp)))
.collect();
Ok(WebDriverResponse::Generic(ValueResponse(
serde_json::to_value(resp_value)?,
)))
},
Err(_) => Err(WebDriverError::new(
ErrorStatus::InvalidSelector,
"Invalid Selector",
"Invalid selector",
)),
}
}
@@ -44,18 +44,12 @@
[test_parent_of_document_node_errors]
expected: FAIL

[test_no_element[css selector-#wontExist\]]
expected: FAIL

[test_find_elements_partial_link_text[<a href=#>partial link&amp;text</a>-k&t\]]
expected: FAIL

[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 bf6ea64

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