Home > Software design >  How can I preload this page with Selenium?
How can I preload this page with Selenium?

Time:12-04

How can I preload all of the information on the page shown in the video below? The page only loads the first 20 applications and as you scroll it will load 20 more when you get to the bottom so 20, 40, 60, etc. Is there a way to use selenium to preload all of the applications? The page is using it's own scroll bar and not the browsers.

https://www.youtube.com/watch?v=WTVyNoQvdJs

Solved using this code

actions = ActionChains(driver)
body = driver.find_element_by_class_name('selected_box')
body.click()
while True:
    try:
        driver.find_element_by_xpath('//*[@id="interview_list"]/div[4]/p/strong')
        break
    except:
        actions.send_keys(Keys.PAGE_DOWN)
        actions.perform()

CodePudding user response:

This can be done in several different ways. In this example, I will be by using the the page down command in the keys function selenium library:

from selenium.webdriver.common.keys import Keys

body = driver.find_element_by_xpath('/html/body')
body.send_keys(Keys.PAGE_DOWN)

Simply put this in a for loop for a specific number of attempts, or embed this within a while loop until desired XPATH is found.

Example using for loop

body = driver.find_element_by_xpath('/html/body')
for i in range(X):
    body.send_keys(Keys.PAGE_DOWN)

Example using while True loop

body = driver.find_element_by_xpath('/html/body')
while True:
    try:
        driver.find_element_by_xpath("DESIRED_XPATH")
        break
    except:
        body.send_keys(Keys.PAGE_DOWN)
  • Related