fix: update handleGetText to use innerText for improved text retrieval (#729)
The handleGetText function now retrieves text using innerText, falling back to textContent if innerText is not available. This change enhances the accuracy of text extraction from elements. Co-authored-by: Honglei Wu <honglei.wu@shopee.com>
This commit is contained in:
+2
-1
@@ -1671,7 +1671,8 @@ async function handleGetAttribute(
|
|||||||
async function handleGetText(command: GetTextCommand, browser: BrowserManager): Promise<Response> {
|
async function handleGetText(command: GetTextCommand, browser: BrowserManager): Promise<Response> {
|
||||||
const page = browser.getPage();
|
const page = browser.getPage();
|
||||||
const locator = browser.getLocator(command.selector);
|
const locator = browser.getLocator(command.selector);
|
||||||
const text = await locator.textContent();
|
const inner = await locator.innerText();
|
||||||
|
const text = inner || (await locator.textContent()) || '';
|
||||||
return successResponse(command.id, { text, origin: page.url() });
|
return successResponse(command.id, { text, origin: page.url() });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user