A
A
Alexander Alexandrov2018-01-04 18:51:48
Layout
Alexander Alexandrov, 2018-01-04 18:51:48

How to take a screenshot of a graphic file (svg, png, etc.) opened in firefox using selenium and geckodriver?

Good day to all!
I ran into one problem, namely, I can’t take a screenshot of an open graphic file (be it svg, png, etc.) in firefox using geckodriver and selenium. If you open a regular web page and execute the code below, everything is fine, but if you do the same for an svg file opened in the browser, then an empty file is returned. If anyone has encountered this problem in geckodriver, tell me which way to dig?

public class Screenshot {

public static void main(String[] args) throws IOException {
    FirefoxDriver driver = new FirefoxDriver();
    driver.get("http://yahoo.com");
    driver.manage().window().maximize();

    File scrFile = driver.getScreenshotAs(OutputType.FILE);  
    FileUtils.copyFile(scrFile, new File("d:\\Selenium\\screenshot2.png"));
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Kirshin, 2019-10-24
@meowto16

Give them a margin.
For example . https://getbootstrap.com/docs/4.3/utilities/spacing/

E
Evgeniy _, 2018-01-12
@GeneD88

Let's start with - what do you want to verify?
If you just need this svg, png, etc - you can open it in a tab - take the current url (the link of this element) and send a GET request and download it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question