I need to scroll to an element and take a screenshot of the page but the driver takes the screenshot before the page is completely scrolled to the element. I've used a time sleep in this way
driver.execute_script("""arguments[0].scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'start' });""", element)
time.sleep(1)
scr = driver.get_screenshot_as_png()
but I really don't want to use sleeps since they are not test-oriented. I've tried to wait for the element to be visible but it didn't work too. Another attempt was to move to the element with ActionChains but it doesn't show the entire element moving on it. Is there a way to wait for the scroll to finish? Besides this specific case of the screenshot, it would be useful knowing a way to wait for the scroll to finish.