storyboard-bridge 0.9.21 → 0.9.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cdp_flow.py +29 -11
- package/package.json +1 -1
package/cdp_flow.py
CHANGED
|
@@ -529,27 +529,45 @@ def main():
|
|
|
529
529
|
step_vars[var] = ""
|
|
530
530
|
elif kind == "drag":
|
|
531
531
|
xpath, direction, steps_count, duration = val[0], val[1], int(val[2]), float(val[3])
|
|
532
|
-
#
|
|
533
|
-
|
|
532
|
+
# Drag implementation: find element, emit mousedown, mousemove sequence, mouseup
|
|
533
|
+
start_x, start_y = page.eval(f"""
|
|
534
534
|
(function() {{
|
|
535
535
|
const el = document.evaluate({json.dumps(xpath)}, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
|
536
536
|
if (!el) return null;
|
|
537
537
|
const rect = el.getBoundingClientRect();
|
|
538
|
-
return
|
|
538
|
+
return [rect.left + rect.width/2, rect.top + rect.height/2];
|
|
539
539
|
}})()
|
|
540
540
|
""")
|
|
541
|
-
if
|
|
542
|
-
start_x, start_y = int(
|
|
541
|
+
if start_x is not None:
|
|
542
|
+
start_x, start_y = int(start_x), int(start_y)
|
|
543
543
|
end_x = start_x + (200 if direction == "right" else -200)
|
|
544
544
|
step_duration = duration / steps_count
|
|
545
|
+
# Emit mousedown
|
|
546
|
+
page.eval(f"""
|
|
547
|
+
(function() {{
|
|
548
|
+
const el = document.evaluate({json.dumps(xpath)}, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
|
549
|
+
const ev = new MouseEvent('mousedown', {{ clientX: {start_x}, clientY: {start_y}, bubbles: true, cancelable: true }});
|
|
550
|
+
el.dispatchEvent(ev);
|
|
551
|
+
}})()
|
|
552
|
+
""")
|
|
553
|
+
time.sleep(0.05)
|
|
554
|
+
# Emit mousemove sequence
|
|
545
555
|
for step_i in range(steps_count):
|
|
546
|
-
x = start_x + (end_x - start_x) * (step_i / steps_count)
|
|
547
|
-
page.
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
})
|
|
556
|
+
x = start_x + (end_x - start_x) * (step_i / (steps_count - 1 if steps_count > 1 else 1))
|
|
557
|
+
page.eval(f"""
|
|
558
|
+
(function() {{
|
|
559
|
+
const ev = new MouseEvent('mousemove', {{ clientX: {int(x)}, clientY: {start_y}, bubbles: true, cancelable: true }});
|
|
560
|
+
document.dispatchEvent(ev);
|
|
561
|
+
}})()
|
|
562
|
+
""")
|
|
552
563
|
time.sleep(step_duration)
|
|
564
|
+
# Emit mouseup
|
|
565
|
+
page.eval(f"""
|
|
566
|
+
(function() {{
|
|
567
|
+
const ev = new MouseEvent('mouseup', {{ clientX: {end_x}, clientY: {start_y}, bubbles: true, cancelable: true }});
|
|
568
|
+
document.dispatchEvent(ev);
|
|
569
|
+
}})()
|
|
570
|
+
""")
|
|
553
571
|
print(f" dragged {direction}")
|
|
554
572
|
time.sleep(delay)
|
|
555
573
|
print("flow complete")
|
package/package.json
CHANGED