This commit is contained in:
@@ -346,20 +346,11 @@ async def interactions_service(
|
||||
if not xpath_selector:
|
||||
raise ValueError("xpath_selector must be a non-empty string")
|
||||
await wait_for_xpath(xpath_selector, timeout_ms=30000)
|
||||
await page.evaluate(
|
||||
"""(xpath) => {
|
||||
const el = document.evaluate(
|
||||
xpath,
|
||||
document,
|
||||
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,
|
||||
)
|
||||
normalized_xpath = xpath_selector[len("xpath=") :] if xpath_selector.startswith("xpath=") else xpath_selector
|
||||
# Use Playwright's click to generate real pointer/mouse events.
|
||||
locator = page.locator(f"xpath={normalized_xpath}").first
|
||||
await locator.wait_for(timeout=30000)
|
||||
await locator.click(force=True, timeout=30000)
|
||||
|
||||
elif action == "type":
|
||||
if text is None:
|
||||
@@ -385,25 +376,11 @@ async def interactions_service(
|
||||
raise ValueError("xpath_selector must be a non-empty string")
|
||||
await wait_for_xpath(xpath_selector, timeout_ms=30000)
|
||||
normalized_xpath = xpath_selector[len("xpath=") :] if xpath_selector.startswith("xpath=") else xpath_selector
|
||||
await page.evaluate(
|
||||
"""({ xpath, value }) => {
|
||||
const el = document.evaluate(
|
||||
xpath,
|
||||
document,
|
||||
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},
|
||||
)
|
||||
locator = page.locator(f"xpath={normalized_xpath}").first
|
||||
await locator.wait_for(timeout=30000)
|
||||
# Prefer fill/type so frameworks see real input events.
|
||||
await locator.click(force=True, timeout=30000)
|
||||
await locator.fill(text, timeout=30000)
|
||||
|
||||
else:
|
||||
raise ValueError(f"Unknown interaction action: {action}")
|
||||
|
||||
Reference in New Issue
Block a user