mirror of
https://github.com/servo/servo.git
synced 2025-07-30 02:30:21 +01:00
Auto merge of #8564 - jgraham:webdriver_attr, r=Ms2ger
Implement Get Element Attribute WebDriver command This intentionally doesn't implement the special handling for boolean attributes yet, since that requires some kind of exhaustive list of all such attributes <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8564) <!-- Reviewable:end -->
This commit is contained in:
commit
7f95693288
4 changed files with 35 additions and 0 deletions
|
@ -15,6 +15,7 @@ pub enum WebDriverScriptCommand {
|
||||||
FindElementsCSS(String, IpcSender<Result<Vec<String>, ()>>),
|
FindElementsCSS(String, IpcSender<Result<Vec<String>, ()>>),
|
||||||
FocusElement(String, IpcSender<Result<(), ()>>),
|
FocusElement(String, IpcSender<Result<(), ()>>),
|
||||||
GetActiveElement(IpcSender<Option<String>>),
|
GetActiveElement(IpcSender<Option<String>>),
|
||||||
|
GetElementAttribute(String, String, IpcSender<Result<Option<String>, ()>>),
|
||||||
GetElementTagName(String, IpcSender<Result<String, ()>>),
|
GetElementTagName(String, IpcSender<Result<String, ()>>),
|
||||||
GetElementText(String, IpcSender<Result<String, ()>>),
|
GetElementText(String, IpcSender<Result<String, ()>>),
|
||||||
GetFrameId(WebDriverFrameId, IpcSender<Result<Option<PipelineId>, ()>>),
|
GetFrameId(WebDriverFrameId, IpcSender<Result<Option<PipelineId>, ()>>),
|
||||||
|
|
|
@ -1092,6 +1092,8 @@ impl ScriptTask {
|
||||||
webdriver_handlers::handle_get_active_element(&page, pipeline_id, reply),
|
webdriver_handlers::handle_get_active_element(&page, pipeline_id, reply),
|
||||||
WebDriverScriptCommand::GetElementTagName(node_id, reply) =>
|
WebDriverScriptCommand::GetElementTagName(node_id, reply) =>
|
||||||
webdriver_handlers::handle_get_name(&page, pipeline_id, node_id, reply),
|
webdriver_handlers::handle_get_name(&page, pipeline_id, node_id, reply),
|
||||||
|
WebDriverScriptCommand::GetElementAttribute(node_id, name, reply) =>
|
||||||
|
webdriver_handlers::handle_get_attribute(&page, pipeline_id, node_id, name, reply),
|
||||||
WebDriverScriptCommand::GetElementText(node_id, reply) =>
|
WebDriverScriptCommand::GetElementText(node_id, reply) =>
|
||||||
webdriver_handlers::handle_get_text(&page, pipeline_id, node_id, reply),
|
webdriver_handlers::handle_get_text(&page, pipeline_id, node_id, reply),
|
||||||
WebDriverScriptCommand::GetFrameId(frame_id, reply) =>
|
WebDriverScriptCommand::GetFrameId(frame_id, reply) =>
|
||||||
|
|
|
@ -203,6 +203,21 @@ pub fn handle_get_name(page: &Rc<Page>,
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn handle_get_attribute(page: &Rc<Page>,
|
||||||
|
pipeline: PipelineId,
|
||||||
|
node_id: String,
|
||||||
|
name: String,
|
||||||
|
reply: IpcSender<Result<Option<String>, ()>>) {
|
||||||
|
reply.send(match find_node_by_unique_id(&*page, pipeline, node_id) {
|
||||||
|
Some(node) => {
|
||||||
|
Ok(node.downcast::<Element>().unwrap().GetAttribute(DOMString::from(name))
|
||||||
|
.map(String::from))
|
||||||
|
},
|
||||||
|
None => Err(())
|
||||||
|
}).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn handle_get_url(page: &Rc<Page>,
|
pub fn handle_get_url(page: &Rc<Page>,
|
||||||
_pipeline: PipelineId,
|
_pipeline: PipelineId,
|
||||||
reply: IpcSender<Url>) {
|
reply: IpcSender<Url>) {
|
||||||
|
|
|
@ -538,6 +538,21 @@ impl Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_element_attribute(&self, element: &WebElement, name: &String) -> WebDriverResult<WebDriverResponse> {
|
||||||
|
let pipeline_id = try!(self.frame_pipeline());
|
||||||
|
|
||||||
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
|
let ConstellationChan(ref const_chan) = self.constellation_chan;
|
||||||
|
let cmd = WebDriverScriptCommand::GetElementAttribute(element.id.clone(), name.clone(), sender);
|
||||||
|
let cmd_msg = WebDriverCommandMsg::ScriptCommand(pipeline_id, cmd);
|
||||||
|
const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap();
|
||||||
|
match receiver.recv().unwrap() {
|
||||||
|
Ok(value) => Ok(WebDriverResponse::Generic(ValueResponse::new(value.to_json()))),
|
||||||
|
Err(_) => Err(WebDriverError::new(ErrorStatus::StaleElementReference,
|
||||||
|
"Unable to find element in document"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_set_timeouts(&mut self, parameters: &TimeoutsParameters) -> WebDriverResult<WebDriverResponse> {
|
fn handle_set_timeouts(&mut self, parameters: &TimeoutsParameters) -> WebDriverResult<WebDriverResponse> {
|
||||||
//TODO: this conversion is crazy, spec should limit these to u32 and check upstream
|
//TODO: this conversion is crazy, spec should limit these to u32 and check upstream
|
||||||
let value = parameters.ms as u32;
|
let value = parameters.ms as u32;
|
||||||
|
@ -731,6 +746,8 @@ impl WebDriverHandler<ServoExtensionRoute> for Handler {
|
||||||
WebDriverCommand::GetActiveElement => self.handle_active_element(),
|
WebDriverCommand::GetActiveElement => self.handle_active_element(),
|
||||||
WebDriverCommand::GetElementText(ref element) => self.handle_element_text(element),
|
WebDriverCommand::GetElementText(ref element) => self.handle_element_text(element),
|
||||||
WebDriverCommand::GetElementTagName(ref element) => self.handle_element_tag_name(element),
|
WebDriverCommand::GetElementTagName(ref element) => self.handle_element_tag_name(element),
|
||||||
|
WebDriverCommand::GetElementAttribute(ref element, ref name) =>
|
||||||
|
self.handle_element_attribute(element, name),
|
||||||
WebDriverCommand::ExecuteScript(ref x) => self.handle_execute_script(x),
|
WebDriverCommand::ExecuteScript(ref x) => self.handle_execute_script(x),
|
||||||
WebDriverCommand::ExecuteAsyncScript(ref x) => self.handle_execute_async_script(x),
|
WebDriverCommand::ExecuteAsyncScript(ref x) => self.handle_execute_async_script(x),
|
||||||
WebDriverCommand::ElementSendKeys(ref element, ref keys) =>
|
WebDriverCommand::ElementSendKeys(ref element, ref keys) =>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue