OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Scroll Page in Slack chat with Selenium using Python

  • Thread starter Thread starter Virrrrrr
  • Start date Start date
V

Virrrrrr

Guest
My script is scraping data from a Slack chat for which i don't have an API so i use Selenium for Webscraping, and when i refresh the page i need to scroll at the bottom of the messages page.

I managed to locate effectively the scroll bar with the selector and I'm trying different ways to move the page down, but it doesn't move by an inch.

Thanks for any suggestion!

Code:
scroll_selector = 'body > div.p-client_container > div > div > div.p-client_workspace_wrapper > div.p-client_workspace > div.p-client_workspace__layout > div:nth-child(2) > div:nth-child(2) > div > div.p-file_drag_drop__container > div.p-workspace__primary_view_body > div > div:nth-child(3) > div > div > div.c-scrollbar__track > div'
            try:
                WebDriverWait(driver, 3).until(EC.presence_of_element_located((By.CSS_SELECTOR, scroll_selector)))
                scrollbar_track = driver.find_element(By.CSS_SELECTOR, scroll_selector)
                print("HTML Element located")
            except TimeoutException:
                print("HTML Element not located")    
            
            # Here different options tried to move the sidebar
            driver.execute_script("arguments[0].click();", scrollbar_track)
            logger.debug("Scroll bar Clicked")

            driver.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", scrollbar_track)
            driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

            scrollbar_track.send_keys(Keys.PAGE_DOWN)

            scrollbar_track.send_keys(Keys.DOWN)
            time.sleep(2)
            scrollbar_track.send_keys(Keys.DOWN)

Code:
<p>My script is scraping data from a Slack chat for which i don't have an API so i use Selenium for Webscraping, and when i refresh the page i need to scroll at the bottom of the messages page.</p>
<p>I managed to locate effectively the scroll bar with the selector and I'm trying different ways to move the page down, but it doesn't move by an inch.</p>
<p>Thanks for any suggestion!</p>
<pre><code>scroll_selector = 'body > div.p-client_container > div > div > div.p-client_workspace_wrapper > div.p-client_workspace > div.p-client_workspace__layout > div:nth-child(2) > div:nth-child(2) > div > div.p-file_drag_drop__container > div.p-workspace__primary_view_body > div > div:nth-child(3) > div > div > div.c-scrollbar__track > div'
try:
WebDriverWait(driver, 3).until(EC.presence_of_element_located((By.CSS_SELECTOR, scroll_selector)))
scrollbar_track = driver.find_element(By.CSS_SELECTOR, scroll_selector)
print("HTML Element located")
except TimeoutException:
print("HTML Element not located")

# Here different options tried to move the sidebar
driver.execute_script("arguments[0].click();", scrollbar_track)
logger.debug("Scroll bar Clicked")

driver.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", scrollbar_track)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

scrollbar_track.send_keys(Keys.PAGE_DOWN)

scrollbar_track.send_keys(Keys.DOWN)
time.sleep(2)
scrollbar_track.send_keys(Keys.DOWN)
</code></pre>
<pre><code>
</code></pre>
 

Latest posts

ن
Replies
0
Views
1
نعمان منذر محمود الجميلي
ن
Top