WebDriver - Unable to take screenshot of the full page with multiple DIVs and FRAMEs

2,483 views
Skip to first unread message

David

unread,
Sep 12, 2012, 4:56:10 AM9/12/12
to seleniu...@googlegroups.com
Hi, 

I am working on automating an web content management system (WCMS), were the webpages are having multiple DIVs and FRAMEs.
When I try to take screenshot it takes only the view port of the whole page it doesn't take the full page. Someone please throw light on how to proceed in
such scenarios.

code snippet:

objWebDriver = new Augmenter().augment(objWebDriver);  
byte[] decodedScreenshot = Base64.decodeBase64(((TakesScreenshot)objWebDriver).getScreenshotAs(OutputType.BASE64).getBytes()); 
FileOutputStream fos = new FileOutputStream(new File(screenshotpath)); 
fos.write(decodedScreenshot); 
fos.close();

Thanks,
David

MartinP

unread,
Sep 12, 2012, 6:26:59 AM9/12/12
to seleniu...@googlegroups.com
Not sure I can help with taking a scrolled screenshot, but the utility method I have to take a screenshot always additionally takes a dump of the page source, so I can see exactly what's in the page internally as well as what it looks like. I've found it very useful to have the page source along with the screen cap, and the page source would have the entire page, not just the view port.

Mike Riley

unread,
Sep 12, 2012, 2:44:40 PM9/12/12
to seleniu...@googlegroups.com
I use something similar and it always shows the full page:

    private WebDriver getScreenshot()
    {
        return new Augmenter().augment(driver);
    }   // getScreenshot

...

            // Not all Webdriver instances can take a screenshot
            WebDriver augmentedDriver = getScreenshot();
            try
            {
                File file;
                String str = System.getProperty("user.dir") + "/"; // Current dir

                file = ((TakesScreenshot) augmentedDriver).getScreenshotAs(
                        OutputType.FILE);
                FileUtils.copyFile(file, new File(filename));
                Reporter.log("<img src=\"file:///" + str + filename +
                             "\" alt=\"\"/><br />");
            }
            catch (Throwable ex1)
            {
                Reporter.log("Unable to capture screentshot to " + filename +
                             "<br/>Got error: " + ex1.getMessage());
            }   // try-catch

Santosh Hulisandra Srikanta

unread,
Sep 12, 2012, 2:48:35 PM9/12/12
to seleniu...@googlegroups.com
Have a basic question why need to use Selenium API for capturing the Screen shot. why cant we some thing in java like this to capture screen shot.

    public void captureScreenShot() throws Exception {
        cnt++;
        driver.switchTo().defaultContent();
        Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
        BufferedImage capture = new Robot().createScreenCapture(screenRect);
        if (Os.equals("win")){
            ImageIO.write(capture, "jpg", new
                    File ("C:\\Automation\\Screen_Shots"+File.separator+"screenshot"+cnt+".jpg"));
        }
        else{
            ImageIO.write(capture, "jpg", new
                    File (File.separator+"screenshot"+cnt+".jpg"));
        }
    }

i use this. i doesn't depend on any case.
If interested just give a try

/santosh

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/aAmJ18tSWQgJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

/Santosh

Mike Riley

unread,
Sep 12, 2012, 4:55:47 PM9/12/12
to seleniu...@googlegroups.com
Well the idea is to copy a shot of the entire page and the entire page may not be visible on the screen.

However, what you suggest (with some changes) is useful for capturing a shot of a system dialog, a displayed PDF file, etc.  So it can be useful in those cases.

Mike

Santosh Hulisandra Srikanta

unread,
Sep 13, 2012, 3:03:30 PM9/13/12
to seleniu...@googlegroups.com
Thnx Mike ... I got why Selenium API is required for Screen shot.

/Santosh

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/W49MtxBsirwJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

/Santosh

David

unread,
Sep 23, 2012, 3:42:14 PM9/23/12
to seleniu...@googlegroups.com
Hi Mike and Santhosh,

The problem is there are two scroll bars in the browser one in the div  and other one in the iframe.
for page without multiple scroll bars the code works fine.

Please give your valuable suggestions, do i need to resize the divs and iframes before taking screenshot if yes how to proceed please let me know. 

Thanks,
David

Mike Riley

unread,
Oct 8, 2012, 2:22:26 PM10/8/12
to seleniu...@googlegroups.com
I think that to help further we would need to see your code and the HTML for that page.  I have never needed to resize anything to get a screenshot.

Mike

Parveen Rao

unread,
Jan 3, 2014, 7:48:03 AM1/3/14
to seleniu...@googlegroups.com, lvsk...@cox.net
Hi All,

I am unable to take screenshot of the complete page while running test scripts on chrome browser(able to take only visible pary screenshot)
I am using chrome 2.27 exe and latest chrome browser and late selenium .net dlls and i also try with lower versions of exe but not able to run scripts.
Please share your comments.

Thanks,
Parveen Kumar

anu jose

unread,
Mar 10, 2014, 7:15:35 AM3/10/14
to seleniu...@googlegroups.com, lvsk...@cox.net
Hi Mike,
 I tried to capture screenshots using the code that you provided, and it executed successfully but did not capture full screenshots ,my code is given below ,please tel me where i am wrong ..

import java.net.URL;

 

import org.apache.commons.io.FileUtils;

import org.openqa.selenium.By;

import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.remote.Augmenter;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.openqa.selenium.remote.RemoteWebDriver;

 

public class Testing {

        private WebDriver getScreenshot() throws MalformedURLException, InterruptedException

     {

               WebDriver driver = new RemoteWebDriver(

                      new URL("http://localhost:4444/wd/hub"),DesiredCapabilities.firefox());

               driver.get("http://www.angelfire.com/super/badwebs/");

      

         return new Augmenter().augment(driver);

     } // getScreenshot

   public void myTest() throws Exception {

    WebDriver augmentedDriver = getScreenshot();

   File screenshot = ((TakesScreenshot)augmentedDriver).

   getScreenshotAs(OutputType.FILE);

   FileUtils.copyFile(screenshot, new File("c:\\tmp\\screenshot1.png"));

   }

}

Thanks & Regards,
Anu
Reply all
Reply to author
Forward
0 new messages