2016-08-15 183 views
-1

我正在尝试使用phantomjs为https://www.google.com捕获简单屏幕截图。屏幕截图显示为空白。我在windows和jar中使用eclipse phantomjsdriver1.1,硒罐所有2.39版本。phantomjs无法从https网站捕获屏幕截图

当我提到网站为http://google时,它会重定向到https并捕获屏幕截图。但我需要它仅以https进行捕获。以下是我的代码。提前致谢 。

import java.io.File; 
import java.io.IOException; 
import java.util.concurrent.TimeUnit; 

import net.anthavio.phanbedder.Phanbedder; 

import org.apache.commons.io.FileUtils; 
import org.openqa.selenium.OutputType; 
import org.openqa.selenium.TakesScreenshot; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.phantomjs.PhantomJSDriver; 
import org.openqa.selenium.phantomjs.PhantomJSDriverService; 
import org.openqa.selenium.remote.DesiredCapabilities; 

public class Schedule { 

    public static void main(String[] args) { 
     File phantomjs = Phanbedder.unpack(); 

     DesiredCapabilities dcaps = new DesiredCapabilities(); 

     dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath()); 
     dcaps.setCapability("takesScreenshot", true); 
     String [] phantomJsArgs = {"---ignore-ssl-errors=yes"}; 
     dcaps.setCapability(
       PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS, 
       phantomJsArgs); 

     PhantomJSDriver driver = new PhantomJSDriver(dcaps); 
     driver.get("https://www.google.com"); 


     driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 

     File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); 
     try { 
     FileUtils.copyFile(scrFile, new File("C:\\Users\\Desktop\\fci\\sample.jpeg"),true); 

     } catch (IOException e) { 
      System.out.println("exception"); 
     } 

     System.out.println("Page title is: " + driver.getTitle()); 

     driver.quit(); 
    } 
} 
+0

您使用哪个PhantomJS版本?我的意思是可执行版本而不是驱动程序版本。 –

+0

我正在使用phanbedder-1.9.7-1.0.0.jar。这个jar里面有exe文件 - phantomjs.exe – dan

+0

这是exe的版本phantomjs \ AppData \ Local \ Temp \ phantomjs-1.9.7 \ phantomjs.exe – dan

回答

0

PhantomJS是一款无头浏览器的含义;你不会看到发生了什么;所做的一切都是在后台完成的。