Scrolling to the next element in Selenium (Python)



  • I'm trying to make a facebook commenting bot in Selenium in Python. I need to scroll down to the text box to make the comment and I have this line of code:

    ActionChains(driver).move_to_element(driver.find_element_by_id('my-id')).perform()
    

    When I run it again it scrolls to the same textbox and I need to scroll to the next one. Is there any way to do it?



  • Just use this:

    element = driver.find_element_by_xpath(textbox_id)
    
    driver.execute_script("arguments[0].scrollIntoView();", element) #Scrolls down until the element is visible
    


Suggested Topics