【问题标题】:Taking snapshots of different webpages using selenium in java在 java 中使用 selenium 拍摄不同网页的快照
【发布时间】:2012-07-15 08:18:56
【问题描述】:

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

    }
}

这是给 this error

我浏览了these links,但找不到解决方案。 请帮我解决这个问题。我是硒新手。

【问题讨论】:

    标签: java selenium-rc webpage-screenshot


    【解决方案1】:

    为什么不这样尝试:

    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

    参考资料:

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多