I think you could condense your code before this:
prior = 0 while True: self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") current = len(WebDriverWait(self.driver, 30).until(EC.presence_of_all_elements_located((By.CLASS_NAME, "x")))) if current == prior: return current prior = current
I skipped all the same lines, moving them all to a loop, which required a while True: to while True: and transfer the condition to the loop (because, unfortunately, Python has no do-while ).
I also sent sleep and print instructions - I'm not sure what their purpose is, but on my own page I found that the same number of elements load whether I sleep between scrolls or not. Also, in my own case, I donβt need to know the score at any time, I just need to know when it has exhausted the list (but I added it to the return variable so that you can get the final score if you happen If you really want to print an interim count , you can print the current text immediately after it is assigned in a loop.
Artoffarfare
source share