0

我有一个 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"); 

    }
}

它给出了这个错误

我浏览了这些链接,但找不到解决方案。请帮我解决这个问题。我是新来的硒。

4

1 回答 1

0

为什么不这样尝试:

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"));

或者在此处查看此链接以获得良好的入门教程:http: //vishnuagrawal.blogspot.com/2011/12/selenium-taking-screenshot-of-webpage.html

参考:

于 2012-07-16T13:15:53.620 回答