Home > other >  How to scroll to the end Selenium Python
How to scroll to the end Selenium Python

Time:10-26

I'm trying to scroll to the end in this page url

When got into the page, I click the button 'Show all 77 products' I got into a popup that shows partially the elements into the popup. Actually this is my code:

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

def getpage(driver):
    driver.get('https://www.binance.com/it/pos')
    sleep(3)
    driver.find_element_by_xpath('//div[@id="savings-lending-pos-expend"]').click()
    sleep(2)
    elem = driver.find_element_by_xpath('//div[@]')
    elem.send_keys(Keys.END)

driver = webdriver.Firefox()
getpage(driver)

I have tried almost everything to work, apart from the solution in the code above, I tried with nu success the current solutions:

driver.execute_script("window.scrollTo(0, Y)") 

and

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

and in this solutions I didn't understand which label to use

label.sendKeys(Keys.PAGE_DOWN);

I tried almost all solutions but none worked. I hope you can help me. Thank you.

CodePudding user response:

You can use ActionChains

from selenium.webdriver.common.action_chains import ActionChains

actions = ActionChains(driver)
actions.send_keys(Keys.PAGE_DOWN)

That will make the page scroll down similar to pressing the Page Down key.

CodePudding user response:

Try like below and confirm:

You can try to find each row and apply scrollIntoView for the same.

# Imports required for Explicit wait:
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

def getpage(driver):
    driver.get('https://www.binance.com/it/pos')
    wait = WebDriverWait(driver,30)
    wait.until(EC.element_to_be_clickable((By.ID,"savings-lending-pos-expend"))).click() // show more option
    i = 0
    try:
        while True:
            options = driver.find_elements_by_xpath("//div[@class='css-n1ers']") // Try to find rows.
            driver.execute_script("arguments[0].scrollIntoView(true);",options[i])
            time.sleep(1)
            i =1
    except:
        pass
    print(i)

getpage(driver)
  • Related