mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Implement tag name selector for FindElement WebDriver command
This commit is contained in:
parent
4128a38936
commit
7d5b324bda
5 changed files with 45 additions and 15 deletions
|
@ -2019,6 +2019,14 @@ impl ScriptThread {
|
||||||
reply,
|
reply,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
WebDriverScriptCommand::FindElementTagName(selector, reply) => {
|
||||||
|
webdriver_handlers::handle_find_element_tag_name(
|
||||||
|
&*documents,
|
||||||
|
pipeline_id,
|
||||||
|
selector,
|
||||||
|
reply,
|
||||||
|
)
|
||||||
|
},
|
||||||
WebDriverScriptCommand::FindElementsCSS(selector, reply) => {
|
WebDriverScriptCommand::FindElementsCSS(selector, reply) => {
|
||||||
webdriver_handlers::handle_find_elements_css(
|
webdriver_handlers::handle_find_elements_css(
|
||||||
&*documents,
|
&*documents,
|
||||||
|
|
|
@ -182,6 +182,25 @@ pub fn handle_find_element_css(
|
||||||
reply.send(node_id).unwrap();
|
reply.send(node_id).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn handle_find_element_tag_name(
|
||||||
|
documents: &Documents,
|
||||||
|
pipeline: PipelineId,
|
||||||
|
selector: String,
|
||||||
|
reply: IpcSender<Result<Option<String>, ()>>,
|
||||||
|
) {
|
||||||
|
let node_id = documents
|
||||||
|
.find_document(pipeline)
|
||||||
|
.ok_or(())
|
||||||
|
.and_then(|doc| {
|
||||||
|
Ok(doc
|
||||||
|
.GetElementsByTagName(DOMString::from(selector))
|
||||||
|
.elements_iter()
|
||||||
|
.next())
|
||||||
|
})
|
||||||
|
.map(|node| node.map(|x| x.upcast::<Node>().unique_id()));
|
||||||
|
reply.send(node_id).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn handle_find_elements_css(
|
pub fn handle_find_elements_css(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
|
|
|
@ -25,6 +25,7 @@ pub enum WebDriverScriptCommand {
|
||||||
ExecuteScript(String, IpcSender<WebDriverJSResult>),
|
ExecuteScript(String, IpcSender<WebDriverJSResult>),
|
||||||
ExecuteAsyncScript(String, IpcSender<WebDriverJSResult>),
|
ExecuteAsyncScript(String, IpcSender<WebDriverJSResult>),
|
||||||
FindElementCSS(String, IpcSender<Result<Option<String>, ()>>),
|
FindElementCSS(String, IpcSender<Result<Option<String>, ()>>),
|
||||||
|
FindElementTagName(String, IpcSender<Result<Option<String>, ()>>),
|
||||||
FindElementsCSS(String, IpcSender<Result<Vec<String>, ()>>),
|
FindElementsCSS(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>, ()>>),
|
||||||
|
|
|
@ -804,17 +804,25 @@ impl Handler {
|
||||||
&self,
|
&self,
|
||||||
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::FindElementCSS(parameters.value.clone(), sender);
|
match parameters.using {
|
||||||
self.browsing_context_script_command(cmd)?;
|
LocatorStrategy::CSSSelector => {
|
||||||
|
let cmd = WebDriverScriptCommand::FindElementCSS(parameters.value.clone(), sender);
|
||||||
|
self.browsing_context_script_command(cmd)?;
|
||||||
|
},
|
||||||
|
LocatorStrategy::TagName => {
|
||||||
|
let cmd =
|
||||||
|
WebDriverScriptCommand::FindElementTagName(parameters.value.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) => {
|
||||||
|
|
|
@ -11,9 +11,6 @@
|
||||||
[test_find_element_partial_link_text[<a href=#> partial link text </a>-link\]]
|
[test_find_element_partial_link_text[<a href=#> partial link text </a>-link\]]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[test_htmldocument[tag name-html\]]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[test_find_element_link_text[<a href=#>link<br>text</a>-link\ntext\]]
|
[test_find_element_link_text[<a href=#>link<br>text</a>-link\ntext\]]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -62,9 +59,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