SeleniumHQ/selenium · error · AttributeError

move_to requires a WebElement

Error message

move_to requires a WebElement

What it means

`PointerActions.move_to` requires its first argument to be a `WebElement`. Passing anything else (a locator string, a Driver, a dict, None) raises `AttributeError` (note: semantically a TypeError, but raised as AttributeError). The pointer cannot move to a non-element target.

Source

Thrown at py/selenium/webdriver/common/actions/pointer_actions.py:89

        return self

    def move_to(
        self,
        element,
        x=0,
        y=0,
        width=None,
        height=None,
        pressure=None,
        tangential_pressure=None,
        tilt_x=None,
        tilt_y=None,
        twist=None,
        altitude_angle=None,
        azimuth_angle=None,
    ):
        if not isinstance(element, WebElement):
            raise AttributeError("move_to requires a WebElement")

        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,
            altitude_angle=altitude_angle,
            azimuth_angle=azimuth_angle,
        )
        return self

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Always pass the result of `driver.find_element(...)`: `move_to(driver.find_element(By.ID, "foo"))`.
  2. Ensure the element was found before moving: guard with a find + None check.
  3. For pointer-move to coordinates, use the lower-level pointer input API or ActionChains move_by_offset.

Example fix

// before
actions.move_to((By.ID, "foo"))  # AttributeError - passed a locator
// after
el = driver.find_element(By.ID, "foo")
actions.move_to(el)
Defensive patterns

Strategy: type-guard

Validate before calling

from selenium.webdriver.remote.webelement import WebElement
el = driver.find_element(By.ID, "foo")
assert isinstance(el, WebElement), "move_to requires a WebElement"
actions.move_to(el)

Type guard

from selenium.webdriver.remote.webelement import WebElement
def is_webelement(value) -> bool:
    return isinstance(value, WebElement)

Try / catch

try:
    actions.move_to(target)
except AttributeError:
    # target was not a WebElement; find it first
    actions.move_to(driver.find_element(By.ID, target))

Prevention

When it happens

Trigger: `move_to(driver.find_element(...))` works, but `move_to("id=foo")`, `move_to(By.ID)`, `move_to(None)`, or `move_to(locator_tuple)` all fail. Calling move_to on a result of a failed find that returned a falsy/empty value.

Common situations: Forgetting to call `find_element` and passing the locator. A stale or shadow-DOM lookup returning a non-WebElement. Mocking elements in tests with a fake object.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/12ec80de83dddaef. Report an issue: GitHub.