Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript error: arguments[0].scrollIntoView is not a function using selenium on python

I'm using Selenium on python and I would like to scroll to an element to click on it. Everywhere I see that the rigth things to do to go directly to the element is to use :

driver = webdriver.Chrome()
driver.get(url)
element = driver.find_elements_by_class_name('dg-button')
driver.execute_script("return arguments[0].scrollIntoView();", element)

But I have this error : "javascript error: arguments[0].scrollIntoView is not a function".

What to I do wrong ? Thanks

like image 372
Chjul Avatar asked Mar 05 '23 05:03

Chjul


1 Answers

Please use the line of code mentioned below instead of the one you are using:

driver.execute_script("arguments[0].scrollIntoView();", element)

Updated answer:
You can also use location_once_scrolled_into_view it gives the coordinates of the element but it does scrolls the element into view as well. You can use it like:

element = driver.find_elements_by_class_name('dg-button')
element.location_once_scrolled_into_view
like image 61
Sameer Arora Avatar answered May 01 '23 14:05

Sameer Arora