简体   繁体   English

为什么我在视口内收到坐标的 MoveTargetOutOfBoundsException 异常? 怎么修?

[英]Why am I getting a MoveTargetOutOfBoundsException for coordinates within the viewport? How to fix?

Using the following code:使用以下代码:

elem = driver.find_element_by_xpath('/html/body/canvas')
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)
actions.move_to_element_with_offset(elem, 185, -35).click().perform()

I am unable to navagate to the desired section of a canvas element and receive this error:我无法导航到画布元素的所需部分并收到此错误:

MoveTargetOutOfBoundsException: move target out of bounds
(Session info: chrome=85.0.4183.102)

My move target is most definitely within the viewport, no scrolling is necessary to make it clickable.我的移动目标绝对在视口内,无需滚动即可使其可点击。 I am using chromedriver and am using the top left corner of the canvas as the start point for my pixel coordinates for move_to_element_with_offset() .我正在使用 chromedriver 并使用画布的左上角作为move_to_element_with_offset()像素坐标的move_to_element_with_offset() Any ideas to fix this?任何想法来解决这个问题? I'm interested in any solutions to click a specified point on a canvas in python, doesn't need to use this same method.我对在 python 中单击画布上指定点的任何解决方案感兴趣,不需要使用相同的方法。

move_to_element_with_offset() move_to_element_with_offset()

move_to_element_with_offset() moves the mouse by an offset of the specified element where offsets are relative to the top-left corner of the element. move_to_element_with_offset()将鼠标移动指定元素的偏移量,其中偏移量相对于元素的左上角。

So from the top-left corner of the <canvas> element if you intent to move by offset (185, -35) where:因此,如果您打算按偏移量(185, -35)移动,则从<canvas>元素的左上角开始,其中:

  • 185 units to the right向右 185 个单位
  • 35 units upwards 35个以上

will be always result into MoveTargetOutOfBoundsException .将始终导致MoveTargetOutOfBoundsException


Solution解决方案

Instead of a negative offset to move upwards you can use a possitive offset to move downwards as follows:您可以使用正偏移量向下移动,而不是使用负偏移量向上移动,如下所示:

actions.move_to_element_with_offset(elem, 35, 35).click().perform()

References参考

You can find a relevant detailed discussion in:您可以在以下位置找到相关的详细讨论:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我在 Python 中收到 ValueError 以及如何修复它? - Why am I getting ValueError in Python and how can I fix it? 为什么我收到 JSON 错误,我该如何解决 - Why am I getting a JSON error and how do I fix it 为什么会出现这些错误以及如何解决它们? - Why am I getting these errors and how to fix them? instabot 错误,为什么我会收到这些错误以及如何解决? - instabot ERROR, Why am I getting these errors and how to fix please? 为什么我会收到属性错误? 我该如何解决? - Why am I getting an attribute error? How can I fix it? 为什么我在尝试检查碰撞时会出现类型错误,我该如何解决? - Why am i getting Type errors when i am trying to check for collision and how can i fix it? 不知道为什么我收到这个错误,我有一个想法,但我不知道如何解决它 - Not sure why I am getting this error, I have an idea but am not sure how to fix it 我收到“SystemExit: 2”错误,如何修复 - I am getting 'SystemExit: 2' error , how to fix it 为什么我会收到“停止迭代”错误,我该如何解决? - Why am I getting the "stop iteration" error and how do I fix this? 我收到一个 KeyError 不知道如何解决它 - I am getting a KeyError an am not sure how to fix it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM