0

I have a cdk-virtual-scroll-viewport container with many elements in it which means not all of its elements are rendered at once. If I scroll, I get more elements and 'lose' the previous ones.

What I want to do is to count the children of this container and process its data.

I have already done the part for counting and processing and it is working as I had checked with elements that fit in this container without needing to scroll.


The problem I have is that because this container doesn't load all data at once, if I get the count using len(), I get only what fits in the current screen I have plus a buffer of elements the developers have added.

I thought of scrolling at the end of this container in a loop until I get an exception that I can't scroll more. This of course is not the best option as it will add each time in the count this extra buffer that it gets loaded even if it is not visible at the time.

This is what I tried, but it doesn't seem to scroll at all in the page. (Checked with headless property off)

    scrollview = driver.find_element_by_tag_name("cdk-virtual-scroll-viewport")

    while True:
        try:
            print("here")

            driver.execute_script("arguments[0].scrollIntoView(true);", scrollview)

            # driver.execute_script("coordinates = arguments[0].getBoundingClientRect();scrollTo(coordinates.x,coordinates.y);", scrollview)
            time.sleep(2)
        except:
            break 

Any suggestions on how I can do this properly? The page I want to write tests for is full of virtual scrollbars so I will need a solution for doing this with selenium/python/javascript and not just doing this manually.

Thanks.

Marialena
  • 763
  • 5
  • 28

0 Answers0