mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
script: Support webdriver's Get Element Text operation for non-HTML elements (#37470)
Fix `WebDriverScriptCommand::GetElementText` similar to https://github.com/servo/servo/pull/37452#discussion_r2146350739, by correctly retrieving rendered text. Testing: `./mach test-wpt -r --log-raw "D:\servo test log\gt_ele_txt.txt" webdriver/tests/classic/get_element_text --product servodriver` Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
parent
810c0e6891
commit
9352a9db7c
3 changed files with 10 additions and 3 deletions
|
@ -2461,7 +2461,7 @@ impl ScriptThread {
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
WebDriverScriptCommand::GetElementText(node_id, reply) => {
|
WebDriverScriptCommand::GetElementText(node_id, reply) => {
|
||||||
webdriver_handlers::handle_get_text(&documents, pipeline_id, node_id, reply)
|
webdriver_handlers::handle_get_text(&documents, pipeline_id, node_id, reply, can_gc)
|
||||||
},
|
},
|
||||||
WebDriverScriptCommand::GetElementInViewCenterPoint(node_id, reply) => {
|
WebDriverScriptCommand::GetElementInViewCenterPoint(node_id, reply) => {
|
||||||
webdriver_handlers::handle_get_element_in_view_center_point(
|
webdriver_handlers::handle_get_element_in_view_center_point(
|
||||||
|
|
|
@ -71,6 +71,7 @@ use crate::script_module::ScriptFetchOptions;
|
||||||
use crate::script_runtime::{CanGc, JSContext as SafeJSContext};
|
use crate::script_runtime::{CanGc, JSContext as SafeJSContext};
|
||||||
use crate::script_thread::ScriptThread;
|
use crate::script_thread::ScriptThread;
|
||||||
|
|
||||||
|
/// <https://w3c.github.io/webdriver/#dfn-get-a-known-element>
|
||||||
fn find_node_by_unique_id(
|
fn find_node_by_unique_id(
|
||||||
documents: &DocumentCollection,
|
documents: &DocumentCollection,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
|
@ -1217,16 +1218,21 @@ pub(crate) fn handle_get_bounding_client_rect(
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <https://w3c.github.io/webdriver/#dfn-get-element-text>
|
||||||
pub(crate) fn handle_get_text(
|
pub(crate) fn handle_get_text(
|
||||||
documents: &DocumentCollection,
|
documents: &DocumentCollection,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
node_id: String,
|
node_id: String,
|
||||||
reply: IpcSender<Result<String, ErrorStatus>>,
|
reply: IpcSender<Result<String, ErrorStatus>>,
|
||||||
|
can_gc: CanGc,
|
||||||
) {
|
) {
|
||||||
reply
|
reply
|
||||||
.send(
|
.send(
|
||||||
find_node_by_unique_id(documents, pipeline, node_id)
|
find_node_by_unique_id(documents, pipeline, node_id).map(|node| {
|
||||||
.map(|node| node.GetTextContent().map_or("".to_owned(), String::from)),
|
node.downcast::<HTMLElement>()
|
||||||
|
.map(|element| element.InnerText(can_gc).to_string())
|
||||||
|
.unwrap_or_else(|| node.GetTextContent().map_or("".to_owned(), String::from))
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1318,6 +1318,7 @@ impl Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <https://w3c.github.io/webdriver/#dfn-get-element-text>
|
||||||
fn handle_element_text(&self, element: &WebElement) -> WebDriverResult<WebDriverResponse> {
|
fn handle_element_text(&self, element: &WebElement) -> WebDriverResult<WebDriverResponse> {
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
let cmd = WebDriverScriptCommand::GetElementText(element.to_string(), sender);
|
let cmd = WebDriverScriptCommand::GetElementText(element.to_string(), sender);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue