Selenium scroll_to_element InvalidArgumentException


I tried to scroll down to the element of the page by using following code:

# coding=utf-8
from selenium import webdriver
from import By
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Firefox()

url = ""

web_element = driver.find_element(By.ID, "filling-in-forms")

actions = ActionChains(driver)

But this code yields an error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python310\lib\site-packages\selenium\webdriver\common\", line 78, in perform
  File "C:\Python310\lib\site-packages\selenium\webdriver\common\actions\", line 88, in perform
    self.driver.execute(Command.W3C_ACTIONS, enc)
  File "C:\Python310\lib\site-packages\selenium\webdriver\remote\", line 435, in execute
  File "C:\Python310\lib\site-packages\selenium\webdriver\remote\", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: unknown variant `wheel`, expected one of `none`, `key`, `pointer` at line 1 column 226

How can I fix the problem?



scroll_to_element(element: selenium.webdriver.remote.webelement.WebElement): If the element is outside the viewport, scrolls the bottom of the element to the bottom of the viewport.

It is defined as:

def scroll_to_element(self, element: WebElement):
    If the element is outside the viewport, scrolls the bottom of the element to the bottom of the viewport.

     - element: Which element to scroll into the viewport.

    return self

As per the API docs I don’t see any issue/error in your code block. However when I execute similar code block using Selenium 4.1.0 using ChromeDriver and Chrome:

web_element = driver.find_element(By.ID, "filling-in-forms")

I face a different error as follows:

Traceback (most recent call last):
  File "C:\Users\debanjan.bhattacharj\Desktop\Python Programs\", line 30, in <module>
AttributeError: 'ActionChains' object has no attribute 'scroll_to_element'

Seems there is a bug in the method defination/implementation.


If your use case is to scroll to an element as an alternative you can use scrollIntoView() inducing WebDriverWait for the for the visibility_of_element_located() as follows:

web_element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.ID, "filling-in-forms")))
driver.execute_script("return arguments[0].scrollIntoView(true);", web_element)

Answered By – undetected Selenium

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published