Skip to content

Commit

Permalink
[py] offsets for moving to an element will originate from in-view cen…
Browse files Browse the repository at this point in the history
…ter point
  • Loading branch information
titusfortner committed Jun 23, 2022
1 parent d09259a commit 64a04f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
19 changes: 1 addition & 18 deletions py/selenium/webdriver/common/actions/pointer_actions.py
Expand Up @@ -56,24 +56,7 @@ def move_to(self, element, x=0, y=0, width=None, height=None, pressure=None,
if not isinstance(element, WebElement):
raise AttributeError("move_to requires a WebElement")

if x or y:
warnings.warn(
"move_to_element_with_offset() currently tries to use the top left corner "
"of the element as the origin; in Selenium 4.3 it will use the in-view "
"center point of the element as the origin.",
DeprecationWarning,
stacklevel=2
)
el_rect = element.rect
left_offset = el_rect['width'] / 2
top_offset = el_rect['height'] / 2
left = -left_offset + (x or 0)
top = -top_offset + (y or 0)
else:
left = 0
top = 0

self.source.create_pointer_move(origin=element, duration=self._duration, x=int(left), y=int(top),
self.source.create_pointer_move(origin=element, duration=self._duration, x=int(x), y=int(y),
width=width, height=height, pressure=pressure,
tangential_pressure=tangential_pressure,
tilt_x=tilt_x, tilt_y=tilt_y, twist=twist,
Expand Down
10 changes: 5 additions & 5 deletions py/test/selenium/webdriver/common/w3c_interaction_tests.py
Expand Up @@ -188,9 +188,9 @@ def test_pen_pointer_properties(driver, pages):
center = _get_inview_center(pointerArea.rect, _get_viewport_rect(driver))
actions.pointer_action.move_to(pointerArea) \
.pointer_down(pressure=0.36, tilt_x=-72, tilt_y=9, twist=86) \
.move_to(pointerArea, x=10, y=40) \
.move_to(pointerArea, x=5, y=10) \
.pointer_up() \
.move_to(pointerArea, x=10, y=50)
.move_to(pointerArea, x=5, y=10)
actions.perform()
events = _get_events(driver)
assert events[3]["type"] == "pointerdown"
Expand Down Expand Up @@ -225,11 +225,11 @@ def test_touch_pointer_properties(driver, pages):
center = _get_inview_center(pointerArea.rect, _get_viewport_rect(driver))
touch_input = PointerInput(interaction.POINTER_TOUCH, "touch")
touch_chain = ActionBuilder(driver, mouse=touch_input)
touch_chain.pointer_action.move_to(pointerArea, x=50, y=25) \
touch_chain.pointer_action.move_to(pointerArea) \
.pointer_down(width=23, height=31, pressure=0.78, tilt_x=21, tilt_y=-8, twist=355) \
.move_to(pointerArea, x=60, y=35, width=39, height=35, pressure=0.91, tilt_x=-19, tilt_y=62, twist=345) \
.move_to(pointerArea, x=10, y=10, width=39, height=35, pressure=0.91, tilt_x=-19, tilt_y=62, twist=345) \
.pointer_up() \
.move_to(pointerArea, x=80, y=50)
.move_to(pointerArea, x=15, y=15)
touch_chain.perform()
events = _get_events(driver)
assert len(events) == 7
Expand Down

0 comments on commit 64a04f8

Please sign in to comment.