简体   繁体   English

在Java中使用Selenium拍摄不同网页的快照

[英]Taking snapshots of different webpages using selenium in java

I have a list of URLs and I need to take their snapshots . 我有一个URL列表,需要对其进行快照。 I am running selenium server using cmd and running following code in eclipse. 我正在使用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"); 

    }
}

It's giving this error 出现此错误

I went through these links but couldn't find a solution . 我浏览了这些链接,但找不到解决方案。 Kindly help me how to fix this . 请帮助我解决此问题。 I am new to selenium . 我是硒的新手。

Why not try it like this: 为什么不这样尝试:

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

alternatively see this link here for a good starting tutorial: http://vishnuagrawal.blogspot.com/2011/12/selenium-taking-screenshot-of-webpage.html 或者,请参见此处的链接以获取良好的入门教程: http : //vishnuagrawal.blogspot.com/2011/12/selenium-taking-screenshot-of-webpage.html

References: 参考文献:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM