2

Simulate the mouse wheel to load all elements.

mouse

I searched Google and tried a lot but failed.

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

# Configuration information
email = "*******"
password = "*******"

driver = webdriver.Chrome()
index_url = "https://quip.com/"
driver.get(url=index_url)
driver.find_element_by_xpath('//*[@id="header-nav-collapse"]/ul/li[9]/a').click()  # click login
time.sleep(1)
driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[1]/form/div/input').send_keys(email)  # input email
driver.find_element_by_xpath('//*[@id="email-submit"]').click()
time.sleep(1)
driver.find_element_by_xpath('/html/body/div/div/form/div/input[2]').send_keys(password)  # input password
driver.find_element_by_xpath('/html/body/div/div/form/button').click()
time.sleep(2)

Pull down scroll

js="var q=document.documentElement.scrollTop=100000" driver.execute_script(js)
time.sleep(3)
driver.maximize_window()
driver.find_element_by_xpath("xpath").send_keys(Keys.DOWN)
js="var q=document.documentElement.scrollTop=10000"
driver.execute_script(js)

The above method does not work.

hakukou
  • 111
  • 1
  • 10

1 Answers1

1

To scroll down the webpage https://testselenium.quip.com/ till the last entry, you have to induce WebDriverWait for the visibility_of_element_located() and you can use the following Locator Strategies:

  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument("start-maximized")
    #chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
    #chrome_options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=chrome_options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
    driver.get("https://quip.com/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.btn-sm[href='/account/login']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='email']"))).send_keys("187069474@qq.com")
    driver.find_element_by_css_selector("button#email-submit").click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='password']"))).send_keys("Huangbo1019@")
    driver.find_element_by_css_selector("button.submit").click()
    driver.execute_script("arguments[0].scrollIntoView(true);", WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.nav-inbox-import-title"))))
    
  • Browser Snapshot:

quip

Here you can find a relevant detailed discussion on What is the difference between the different scroll options?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • But I want to scroll a little to the bottom,I need to load all hrefs – hakukou Sep 23 '19 at 07:37
  • @hakukou That's the bottom, see the item with text as **Get Started on Quip**. Of coarse the scroll to the element happens after all the previous elements (read as _hrefs_) have been loaded. Now how to collect the _hrefs_ needs a different strategy all together and you may need to raise a new question with your new requirement. – undetected Selenium Sep 23 '19 at 07:59
  • hi,I added a question, if you know, please help me, thank you very much.https://stackoverflow.com/questions/58058346/selenium-how-to-scroll-down-to-get-all-the-link – hakukou Sep 23 '19 at 08:23