Search code examples
pythonselenium

Python Selenium press down arrow to dispay all page contents


I have opened a web page using webdriver (selenium & python). All the items on the page do not load unless I press the space key 8 times or hold the down arrow.

driver.get('https://www.some-website.html')
driver.find_element_by_class_name('profiles').click()

I have googled for a solution with ActionChains but I am unable to find a solution. Thank you in advance for your help.


Solution

  • Pressing a space would probably just scroll the page to the very bottom which probably triggers loading additional content. What you can do is is to use ActionChains() to press SPACE 8 times with a delay:

    import time
    
    from selenium.webdriver.common.action_chains import ActionChains
    
    actions = ActionChains(driver)
    for _ in range(8):
        actions.send_keys(Keys.SPACE).perform()
        time.sleep(1)
    

    Or, you may scroll into view of the "footer" element (or something else in the bottom, depending on the particular web-site):

    footer = driver.find_element_by_tag_name("footer")
    for _ in range(8):
        driver.execute_script("arguments[0].scrollIntoView();", footer)
        time.sleep(1)
    

    These are all guesses though, it is difficult to provide a reliable working solution without actually trying them out on the actual webpage you are working with.