Search code examples
pythonseleniumselenium-webdriverselenium-chromedriverwebautomation

How do I scroll down when there are multiple windows within a browser that has scroll bars using python selenium


So after clicking a button the pop up window (in the picture) popped up, and it has 2 elements with scroll bars. I want to scroll down on the main, right, element.

browser.execute_script("window.scrollBy(0, 10000)","")

This line of code does not work. It did not throw an error, but it had no effect.


Solution

  • Here is the logic to scroll and perform operations on each row.

    driver.find_element_by_xpath("(//div[@clas='pagec_list_wrapper]/div[@class='pagelist_item])[last()]").location_once_scrolled_into_view
    time.sleep(2)
    driver.find_element_by_xpath("(//div[@clas='pagec_list_wrapper]/div[@class='pagelist_item])[last()]").location_once_scrolled_into_view
    
    # get the number of rows
    rows = driver.find_elements_by_xpath("//div[@clas='pagec_list_wrapper]/div[@class='pagelist_item]")
    # now you can access each row here in for loop
    for rowNumber in range(len(rows)):
        # scroll to the row
        driver.find_element_by_xpath("(//div[@clas='pagec_list_wrapper]/div[@class='pagelist_item])[" + str(rowNumber+1) "]").location_once_scrolled_into_view
        # if you want to click on the button (+) for that user
        driver.find_element_by_xpath("((//div[@clas='pagec_list_wrapper]/div[@class='pagelist_item])[" + str(rowNumber+1) "]//span[@class='ui_button_icon'])[1]").click()
        # you can use row element for any action with in the row
        row.xxxxxx