当第二次执行鼠标操作时,我得到MoveTargetOutOfBounds Exeption



Im使用selenium webdriver中的ActionChains点击画布上的特定位置。第一次它工作,但第二次,它抛出了一个异常:

actions = ActionChains(driver)
actions.move_by_offset(650,500).click().perform()
time.sleep(2)
actions.move_by_offset(700,500).click().perform()

即使我将second 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)

请注意:我点击的地方是一个画布-当按下鼠标右键时,我甚至无法在上面获得菜单。这个问题是否与这个画布从webdriver获得焦点有关?

这里有两个问题:您需要使用预订操作

actions.reset_actions()

鼠标从最后一点开始移动,因此给定值(700500(会将其移动到屏幕之外=异常这是工作代码:

actions = ActionChains(driver)
actions.move_by_offset(650,500).click().perform()
actions.reset_actions()
actions.move_by_offset(80,0).click().perform()

相关内容

  • 没有找到相关文章

最新更新