在java中使用selenium拍摄不同网页的快照

在java中使用selenium拍摄不同网页的快照,java,selenium-rc,webpage-screenshot,Java,Selenium Rc,Webpage Screenshot,我有一个URL列表,我需要拍摄它们的快照。 我使用cmd运行selenium服务器,并在eclipse中运行以下代码 package com.example.tests; import com.thoughtworks.selenium.DefaultSelenium; import com.thoughtworks.selenium.Selenium; public class MainClass { void func(String url, String file)

我有一个URL列表,我需要拍摄它们的快照。 我使用cmd运行selenium服务器,并在eclipse中运行以下代码

package com.example.tests;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class MainClass {


    void func(String url, String file)
    {
        Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", url);
        selenium.start();

        selenium.windowMaximize(); 

        selenium.open("/");
        selenium.waitForPageToLoad("30000");


        System.out.println("laoded\n");
    //  selenium.wait();
        String file1= "C:\\test\\"+file+".png";
        String file2= "C:\\test\\"+file+"2.png";
        selenium.captureScreenshot(file1);
        selenium.captureEntirePageScreenshot(file2, "");

        selenium.stop();

    }


    public static void main(String[] args)
    {

        MainClass demo = new MainClass();

        demo.func("http://www.facebook.com","face"); 

        demo.func("www.reddit.com","reddit"); 

    }
}
它在给予

我看了一遍,但找不到解决办法。
请帮我解决这个问题。我是硒新手。

为什么不这样尝试呢:

WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
或者,请参见此处的链接,以获取良好的入门教程:

参考文献:


谢谢,它工作正常,但在IE的情况下,它会给出此错误。没关系。现在修好了。我在这里找到了解决办法。