Skip to content
Permalink
Browse files

Implement tag name selector for FindElementFromElement WebDriver command

  • Loading branch information...
georgeroman committed Jun 17, 2019
1 parent dec73e4 commit 616a81fb279a95019b321233d1d65ddd467f927d
@@ -2052,6 +2052,15 @@ impl ScriptThread {
reply,
)
},
WebDriverScriptCommand::FindElementElementTagName(selector, element_id, reply) => {
webdriver_handlers::handle_find_element_element_tag_name(
&*documents,
pipeline_id,
element_id,
selector,
reply,
)
},
WebDriverScriptCommand::FindElementElementsCSS(selector, element_id, reply) => {
webdriver_handlers::handle_find_element_elements_css(
&*documents,
@@ -259,6 +259,26 @@ pub fn handle_find_element_element_css(
reply.send(node_id).unwrap();
}

pub fn handle_find_element_element_tag_name(
documents: &Documents,
pipeline: PipelineId,
element_id: String,
selector: String,
reply: IpcSender<Result<Option<String>, ()>>,
) {
let node_id = 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))
.elements_iter()
.next()),
None => Err(()),
})
.map(|node| node.map(|x| x.upcast::<Node>().unique_id()));
reply.send(node_id).unwrap();
}

pub fn handle_find_element_elements_css(
documents: &Documents,
pipeline: PipelineId,
@@ -29,6 +29,7 @@ pub enum WebDriverScriptCommand {
FindElementsCSS(String, IpcSender<Result<Vec<String>, ()>>),
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>, ()>>),
FocusElement(String, IpcSender<Result<(), ()>>),
GetActiveElement(IpcSender<Option<String>>),
@@ -950,21 +950,32 @@ 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::FindElementElementCSS(
parameters.value.clone(),
element.id.clone(),
sender,
);

self.browsing_context_script_command(cmd)?;
match parameters.using {
LocatorStrategy::CSSSelector => {
let cmd = WebDriverScriptCommand::FindElementElementCSS(
parameters.value.clone(),
element.id.clone(),
sender,
);
self.browsing_context_script_command(cmd)?;
},
LocatorStrategy::TagName => {
let cmd = WebDriverScriptCommand::FindElementElementTagName(
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) => {
@@ -62,9 +62,6 @@
[test_find_element_partial_link_text[<a href=#>partial link text</a>-k t\]]
expected: FAIL

[test_find_element[tag name-a\]]
expected: FAIL

[test_xhtml_namespace[partial link text-link text\]]
expected: FAIL

0 comments on commit 616a81f

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