This commit is contained in:
@@ -346,20 +346,11 @@ async def interactions_service(
|
|||||||
if not xpath_selector:
|
if not xpath_selector:
|
||||||
raise ValueError("xpath_selector must be a non-empty string")
|
raise ValueError("xpath_selector must be a non-empty string")
|
||||||
await wait_for_xpath(xpath_selector, timeout_ms=30000)
|
await wait_for_xpath(xpath_selector, timeout_ms=30000)
|
||||||
await page.evaluate(
|
normalized_xpath = xpath_selector[len("xpath=") :] if xpath_selector.startswith("xpath=") else xpath_selector
|
||||||
"""(xpath) => {
|
# Use Playwright's click to generate real pointer/mouse events.
|
||||||
const el = document.evaluate(
|
locator = page.locator(f"xpath={normalized_xpath}").first
|
||||||
xpath,
|
await locator.wait_for(timeout=30000)
|
||||||
document,
|
await locator.click(force=True, timeout=30000)
|
||||||
null,
|
|
||||||
XPathResult.FIRST_ORDERED_NODE_TYPE,
|
|
||||||
null
|
|
||||||
).singleNodeValue;
|
|
||||||
if (!el) throw new Error(`No element for xpath: ${xpath}`);
|
|
||||||
el.click();
|
|
||||||
}""",
|
|
||||||
xpath_selector[len("xpath=") :] if xpath_selector.startswith("xpath=") else xpath_selector,
|
|
||||||
)
|
|
||||||
|
|
||||||
elif action == "type":
|
elif action == "type":
|
||||||
if text is None:
|
if text is None:
|
||||||
@@ -385,25 +376,11 @@ async def interactions_service(
|
|||||||
raise ValueError("xpath_selector must be a non-empty string")
|
raise ValueError("xpath_selector must be a non-empty string")
|
||||||
await wait_for_xpath(xpath_selector, timeout_ms=30000)
|
await wait_for_xpath(xpath_selector, timeout_ms=30000)
|
||||||
normalized_xpath = xpath_selector[len("xpath=") :] if xpath_selector.startswith("xpath=") else xpath_selector
|
normalized_xpath = xpath_selector[len("xpath=") :] if xpath_selector.startswith("xpath=") else xpath_selector
|
||||||
await page.evaluate(
|
locator = page.locator(f"xpath={normalized_xpath}").first
|
||||||
"""({ xpath, value }) => {
|
await locator.wait_for(timeout=30000)
|
||||||
const el = document.evaluate(
|
# Prefer fill/type so frameworks see real input events.
|
||||||
xpath,
|
await locator.click(force=True, timeout=30000)
|
||||||
document,
|
await locator.fill(text, timeout=30000)
|
||||||
null,
|
|
||||||
XPathResult.FIRST_ORDERED_NODE_TYPE,
|
|
||||||
null
|
|
||||||
).singleNodeValue;
|
|
||||||
if (!el) throw new Error(`No element for xpath: ${xpath}`);
|
|
||||||
el.focus?.();
|
|
||||||
if ('value' in el) {
|
|
||||||
el.value = value;
|
|
||||||
el.dispatchEvent(new Event('input', { bubbles: true }));
|
|
||||||
el.dispatchEvent(new Event('change', { bubbles: true }));
|
|
||||||
}
|
|
||||||
}""",
|
|
||||||
{"xpath": normalized_xpath, "value": text},
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Unknown interaction action: {action}")
|
raise ValueError(f"Unknown interaction action: {action}")
|
||||||
|
|||||||
Reference in New Issue
Block a user