2

Trying to scroll down to the bottom of the page https://silpo.ua/offers/?categoryId=13 but there is no result (no movements)

My code:

import bs4
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

URL = "https://silpo.ua/offers/?categoryId=13"
driver = webdriver.Firefox()
driver.get(URL)

page = driver.find_element_by_tag_name("html")
page.send_keys(Keys.PAGE_DOWN)

html = driver.page_source
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
alexmosk25
  • 134
  • 1
  • 2
  • 12
  • Possible duplicate of [How can I scroll a web page using selenium webdriver in python?](https://stackoverflow.com/questions/20986631/how-can-i-scroll-a-web-page-using-selenium-webdriver-in-python) – JeffC Dec 01 '18 at 16:48
  • Is this because selenium can't click on links that aren't in the viewport? We shouldn't need to do this anymore. – pguardiario Dec 01 '18 at 22:42

2 Answers2

4

You can move to the copyright class element at the bottom using actions.move_to_element

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

url ="https://silpo.ua/offers/?categoryId=13"
driver = webdriver.Chrome()
driver.get(url)
element = driver.find_element_by_css_selector(".copyrights")
actions = ActionChains(driver)
actions.move_to_element(element).perform()

You can vary this, for example, say you wanted to go to last product:

element = driver.find_elements_by_css_selector(".product-list__item-content")[-1]
actions = ActionChains(driver)
actions.move_to_element(element).perform()
QHarr
  • 83,427
  • 12
  • 54
  • 101
4

There are several approaches to scroll down to the bottom of the page. As per the url https://silpo.ua/offers/?categoryId=13 the copyright message is located at the bottom of the page. So you can use scrollIntoView() method to scroll the copyright message within the Viewport as follows:

from selenium import webdriver
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

URL = "https://silpo.ua/offers/?categoryId=13"
driver = webdriver.Firefox(executable_path=r'C:\WebDrivers\geckodriver.exe')
driver.get(URL)
copyright = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.copyrights")))
driver.execute_script("return arguments[0].scrollIntoView(true);", copyright)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Thank you, sir! How can I consistently jump to all element with selector "product-list__item-image" ??? I can jump to the first, but can't jump to the next. – alexmosk25 Dec 01 '18 at 15:59