mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Implement tag name selector for FindElementFromElement WebDriver command
This commit is contained in:
parent
dec73e4cea
commit
616a81fb27
5 changed files with 54 additions and 16 deletions
|
@ -2052,6 +2052,15 @@ impl ScriptThread {
|
||||||
reply,
|
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) => {
|
WebDriverScriptCommand::FindElementElementsCSS(selector, element_id, reply) => {
|
||||||
webdriver_handlers::handle_find_element_elements_css(
|
webdriver_handlers::handle_find_element_elements_css(
|
||||||
&*documents,
|
&*documents,
|
||||||
|
|
|
@ -259,6 +259,26 @@ pub fn handle_find_element_element_css(
|
||||||
reply.send(node_id).unwrap();
|
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(
|
pub fn handle_find_element_elements_css(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
|
|
|
@ -29,6 +29,7 @@ pub enum WebDriverScriptCommand {
|
||||||
FindElementsCSS(String, IpcSender<Result<Vec<String>, ()>>),
|
FindElementsCSS(String, IpcSender<Result<Vec<String>, ()>>),
|
||||||
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>, ()>>),
|
||||||
FindElementElementsCSS(String, String, IpcSender<Result<Option<String>, ()>>),
|
FindElementElementsCSS(String, String, IpcSender<Result<Option<String>, ()>>),
|
||||||
FocusElement(String, IpcSender<Result<(), ()>>),
|
FocusElement(String, IpcSender<Result<(), ()>>),
|
||||||
GetActiveElement(IpcSender<Option<String>>),
|
GetActiveElement(IpcSender<Option<String>>),
|
||||||
|
|
|
@ -950,21 +950,32 @@ 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::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() {
|
match receiver.recv().unwrap() {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
|
|
|
@ -62,9 +62,6 @@
|
||||||
[test_find_element_partial_link_text[<a href=#>partial link text</a>-k t\]]
|
[test_find_element_partial_link_text[<a href=#>partial link text</a>-k t\]]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[test_find_element[tag name-a\]]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[test_xhtml_namespace[partial link text-link text\]]
|
[test_xhtml_namespace[partial link text-link text\]]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue