第二次执行鼠标操作时,我得到 MoveTargetOutOfBounds Exeption
When performing mouse action for second time, I get MoveTargetOutOfBounds Exeption
我正在使用来自 selenium webdriver 的 ActionChains 单击 canvas 上的特定位置。
第一次它工作,但第二次,它抛出异常:
actions = ActionChains(driver)
actions.move_by_offset(650,500).click().perform()
time.sleep(2)
actions.move_by_offset(700,500).click().perform()
即使我将秒 move_by_offset 中的值更改为 (0,0),它也会出错:
Traceback (most recent call last):
File "/home/*****1.py", line 55, in <module>
actions.move_by_offset(700,500).click().perform()
File "/home/kuba/*****/action_chains.py", line 80, in perform
self.w3c_actions.perform()
File "/home/kuba/******/common/actions/action_builder.py", line 76, in perform
self.driver.execute(Command.W3C_ACTIONS, enc)
File "/home/*****python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/*******/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: move target out of bounds
(Session info: chrome=84.0.4147.89)
请注意:我点击的地方是 canvas - 我什至找不到按下鼠标右键时显示菜单。
这个问题是否与这个 canvas 得到 webdriver 的关注有关?
这里有两个问题:
您需要使用
保留操作
actions.reset_actions()
鼠标从最后一个点开始移动,因此给定值 (700,500) 将其移出屏幕 = 异常
这是工作代码:
actions = ActionChains(driver)
actions.move_by_offset(650,500).click().perform()
actions.reset_actions()
actions.move_by_offset(80,0).click().perform()
我正在使用来自 selenium webdriver 的 ActionChains 单击 canvas 上的特定位置。 第一次它工作,但第二次,它抛出异常:
actions = ActionChains(driver)
actions.move_by_offset(650,500).click().perform()
time.sleep(2)
actions.move_by_offset(700,500).click().perform()
即使我将秒 move_by_offset 中的值更改为 (0,0),它也会出错:
Traceback (most recent call last):
File "/home/*****1.py", line 55, in <module>
actions.move_by_offset(700,500).click().perform()
File "/home/kuba/*****/action_chains.py", line 80, in perform
self.w3c_actions.perform()
File "/home/kuba/******/common/actions/action_builder.py", line 76, in perform
self.driver.execute(Command.W3C_ACTIONS, enc)
File "/home/*****python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/*******/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: move target out of bounds
(Session info: chrome=84.0.4147.89)
请注意:我点击的地方是 canvas - 我什至找不到按下鼠标右键时显示菜单。 这个问题是否与这个 canvas 得到 webdriver 的关注有关?
这里有两个问题: 您需要使用
保留操作actions.reset_actions()
鼠标从最后一个点开始移动,因此给定值 (700,500) 将其移出屏幕 = 异常 这是工作代码:
actions = ActionChains(driver)
actions.move_by_offset(650,500).click().perform()
actions.reset_actions()
actions.move_by_offset(80,0).click().perform()