I am writing a parser. On the page there is a button, by clicking on which loading of the goods takes place. Since pressing can only be performed on the visible element, I use the move_to_element method to scroll to the element. Everything works well. But starting with 37 downloads of the product, the element seems to be "scrolling" and is now in the upper part, hiding under the top search and not allowing to click on it. Why is this happening and how to fix it? Normal scrolling to an item enter image description here

Problem scrolling

enter image description here

https://www.dns-shop.ru/catalog/17a8a01d16404e77/smartfony/?p=40&i=1

Code:

while(True): catalog_items_more = WebDriverWait(driver, 60).until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".catalog-items-more:not(.hidden)"))) webdriver.ActionChains(driver).move_to_element(catalog_items_more).perform(); catalog_items_more.click() 

Or how to click on an element without scrolling?

    1 answer 1

     try: self.selenium.execute_script("window.scrollTo(0, document.body.scrollHeight);") # на экран вниз time.sleep(1) self.selenium.find_element_by_xpath('//*[name()="path"][@class="active"]').click() # выбор мест except NoSuchElementException: time.sleep(1) self.selenium.execute_script("window.scrollTo(0, -250);") # идем вверх 

    The point is this, if you don’t see the element, then you leaf through it. You can not scroll through the entire height of the document document.body.scrollHeight

    Scroll to the element try this:

     from selenium.webdriver.common.action_chains import ActionChains element = driver.find_element_by_id("my-id") actions = ActionChains(driver) actions.move_to_element(element).perform() 

    Or another way:

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