[英]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()
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>
元素的左上角开始,其中:
will be always result into MoveTargetOutOfBoundsException
.将始终导致
MoveTargetOutOfBoundsException
。
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()
You can find a relevant detailed discussion in:您可以在以下位置找到相关的详细讨论:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.