Home > OS >  how can i get a Screenshot of full post from Facebook page
how can i get a Screenshot of full post from Facebook page

Time:06-22

enter image description herewhen i did the screenshot of each post from Facebook page i get just a part from post after zoom out.

code:

post = browser.find_element_by_xpath("class")
browser.execute_script("document.body.style.zoom='80%'")
screen = post.screenshot_as_png
im = Image.open(BytesIO(screen))
im.save('image.png')

CodePudding user response:

Screenshot by XPATH:

Instead of trying to format the page to take a screenshot, Selenium has a way to capture a screenshot by the XPATH. See the below code:

post = browser.find_element_by_xpath("class")
post.screenshot("post.png")

CodePudding user response:

Solutuion

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;

import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;

public class ScreenshotDemo {
    public static void main(String[] args) throws IOException {
        //set the location of chrome browser
        System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
        
        // Initialize browser
        WebDriver driver = new ChromeDriver();
        
        //navigate to url
        driver.get("https://demoqa.com");

        // capture screenshot and store the image
        Screenshot s=new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
        ImageIO.write(s.getImage(),"PNG",new File("C:\\projectScreenshots\\fullPageScreenshot.png"));
        
        //closing the webdriver
        driver.close();
    }
}

I am sure you can change it python

  • Related