2016-08-15 10 views
-1

私はhttps://www.google.comのphantomjsを使って簡単なスクリーンショットをキャプチャしようとしています。スクリーンショットが空白になっています。私は窓と瓶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を使用しています。このジャーの中にはウィンドウ用のexeがあります - phantomjs.exe – dan

+0

これはexeファントムのバージョンです \ AppData \ Local \ Temp \ phantomjs-1.9.7 \ phantomjs.exe – dan

答えて

0

PhantomJSは、ヘッドレスブラウザの意味です。あなたは何が起こっているか見ることができません。完了したことはすべてバックグラウンドで行われます。

関連する問題