基本上,我的页面具有以下规范:
<html>
...
<iframe id="lvl1">
<html>
<iframe id="lvl2">
<div>Double Click Me !</div>
</iframe>
</html>
<iframe>
</html>
我无法双击给定的元素(使用 ActionChain),因为当我这样做时会引发 MoveTargetOutOfBoundsException。
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import MoveTargetOutOfBoundsException
try:
action = ActionChains(context.browser)
action.double_click(webelement)
action.perform()
except MoveTargetOutOfBoundsException:
context.browser.switch_to_default_content()
context.browser.switch_to_frame("lvl1")
context.browser.switch_to_frame("lvl2")
actions = ActionChains(context.browser)
my_locationXY = emoji.get_location()
actions.move_to_element_with_offset(frame, my_locationXY["x"], my_locationXY["y"]).double_click().perform()
我根据此处发布的最后一条评论创建了前面的片段。