0

I am trying to scrape data off a website using Selenium in Python, where the data only appears once I click a 'Details' button, the problem is that this button isn't initially visible and requires scrolling on an internal scroll bar (circled in red)

For reference, here's the website: https://www.abt-sportsline.com/tuning/configurator#80706385!43C6B47

The goal is to scroll this internal scroll bar so I can click the button and view/scrape the data.

Here's my initial code:

scrollBar = driver.find_element(By.XPATH,'//*[@id="mCSB_1_dragger_vertical"]/div')
driver.execute_script("arguments.scrollBy(0,arguments[0].scrollHeight)", scrollBar)
temp_element = in_tab_object.find_element(By.CSS_SELECTOR,"div > div > div > div.row > div.col-xs-12.product-details > div > div.text-right.details-link > span.icon-ArrowRight")
temp_element.click()

This does not scroll the internal bar at all and I get the following error:

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

I have another idea of solving this problem, where I find the scrollbar container and click the bottom of it, hence, scrolling all the way down, but I am unsure how to specify clicking local coordinates of a container.

Some help would be appreciated!

1
  • You'll probably need to select the frame which has the scroll bar first and then start scrolling on it. Commented May 11, 2022 at 2:47

2 Answers 2

1

You could try ActionChains.

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains as AC

dr = webdriver.Chrome("[path_to_your_chromedriver]")

dr.get("https://www.abt-sportsline.com/tuning/configurator#80713308!5972E27")

aa = dr.find_element_by_id("mCSB_1_scrollbar_vertical")

action = AC(dr)

action.click_and_hold(aa).move_by_offset(0,1).perform()

# Don't forget to release the click_and_hold, for example with:

action.reset_actions()

This does not work very well, however. I think it's something to do with that it is a custom scroll bar.

Read more about action chains here:

https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.common.action_chains

.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! While this probably isn't the best solution, it worked for me!
1

As it is not inside frame, You can easily use scrolled_once_into_view which is the same as scrollIntoView() in js.

for instance:

element = driver.find_element('xpath', "DETAILS_BUTTON_XPATH")
element.scrolled_once_into_view  # Ignore IDE errors for this command. It is working well. 

Alternatively you can use following (using JS command):

element = driver.find_element('xpath', "DETAILS_BUTTON_XPATH")
driver.execute_script("arguments[0].scrollIntoView();", element)

3 Comments

Hey Mohammad, appreciate the response however I am getting the following error for both methods: AttributeError: 'WebElement' object has no attribute 'execute_script' Same error with the first method but obviously the attribute is 'scrolled_once_into_view"
` 'WebElement' object has no attribute 'execute_script'` shows that you're passing once_scrolled_into_view the driver object. You should pass it to the element object. Could you share your code you've written based on my answer?
scrollBar = driver.find_element(By.XPATH,'//*[@id="bmf-tc"]/div/div[2]/div/div/div[2]/div/div/div/div[2]/div/div[3]/div[1]/div/div/div[3]/div[3]') scrollBar.scrolled_once_into_view

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.