簡體   English   中英

在Java中使用Selenium拍攝不同網頁的快照

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

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

或者,請參見此處的鏈接以獲取良好的入門教程: http : //vishnuagrawal.blogspot.com/2011/12/selenium-taking-screenshot-of-webpage.html

參考文獻:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM