1

I have the following code which is supposed to scroll down the page and then click a button. When I run my script, I can see that the page does scroll until the element is at the very bottom of the page, but then the script fails when it gets time to click on that button and I get this error:

selenium.common.exceptions.ElementNotInteractableException: Message: Element could not be scrolled into view

I have tried using these methods:

  • driver.execute_script("arguments[0].scrollIntoView();", element)
  • driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_xpath(xpath of element))
  • actions.move_to_element(element)

All of these methods have the same result: the page will scroll to the element, but when it is time to click on the element it complains that the element could not be scrolled into view.

CODE:

hide_partial_rows_button_per_100 = driver.find_element_by_xpath('//button[@id="per_poss_toggle_partial_table"]')
#driver.execute_script("arguments[0].scrollIntoView();",driver.find_element_by_xpath('//button[@id="per_poss_toggle_partial_table"]'))
#driver.execute_script("arguments[0].scrollIntoView();",hide_partial_rows_button_per_100)

actions.move_to_element(hide_partial_rows_button_per_100)
actions.perform
hide_partial_rows_button_per_100.click()

LINK TO PAGE I'M WORKING ON: https://www.basketball-reference.com/players/v/valanjo01.html

Someone on this site had a similar question but they were using JavaScript instead of Python and they added a time.sleep(1) between scrolling to the element and clicking on it, this did not work for me.

As said above, I've tried both the driver.execute_script("arguments[0].scrollIntoView();",element) and actions.move_to_element(element) methods and both work for scrolling, but when it is time to click on the element it complains that it cannot be scrolled into view.

3
  • Can you share a link to the page you working on? Commented Nov 21, 2022 at 20:33
  • Does this answer your question? Scrolling to element using webdriver? Commented Nov 21, 2022 at 20:34
  • I have added the link to the page I'm working on. Commented Nov 21, 2022 at 20:37

1 Answer 1

0

You can apply location_once_scrolled_into_view method to perform scrolling here.
The following code worked for me:

from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = Options()
options.add_argument("start-maximized")
options.add_argument('--disable-notifications')

caps = DesiredCapabilities().CHROME
caps["pageLoadStrategy"] = "eager"

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, desired_capabilities=caps, service=webdriver_service)
wait = WebDriverWait(driver, 20)

url = "https://www.basketball-reference.com/players/v/valanjo01.html"
driver.get(url)
element = wait.until(EC.presence_of_element_located((By.XPATH, '//button[@id="per_poss_toggle_partial_table"]')))
element.location_once_scrolled_into_view
Sign up to request clarification or add additional context in comments.

5 Comments

Adding the element.location_once_scrolled_into_view has solved one error but now I'm getting this one: selenium.common.exceptions.ElementClickInterceptedException: Message: Element <button id="per_poss_toggle_partial_table" class="tooltip" type="button"> is not clickable at point (419,7) because another element <span> obscures it Do you know what that means? I'm still new to programming.
EDIT: I was able to find the solution for my comment above, the element.location_once_scrolled_into_view did the trick for what was asked here, thank you!
So, as I understand your problem is now resolved or you still need some help?
My problem is resolved, thank you.
Great! Nice to know that 👍

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.