Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

javascript - Selenium - Wait for the ScrollIntoView to finish

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.

question from:https://stackoverflow.com/questions/65844253/selenium-wait-for-the-scrollintoview-to-finish

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
public static void fullScren(String filename) throws IOException
{

        Screenshot myScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(100)).takeScreenshot(driver);
        ImageIO.write(myScreenshot.getImage(),"PNG",new File("src/main/java/ScreenShots/" + filename + ".jpg"));
    }

You have to use this scroll down and take full screen shot by selenium


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...