我正在尝试使用phantomjs为https://www.google.com捕获简单的屏幕截图。屏幕截图显示为空白。我在windows和jar中使用eclipse phantomjsdriver1.1,selenium jar所有2.39版本。
当我将网站称为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 :(得分:0)
PhantomJS是无头浏览器的意思;你无法看到发生的事情;所做的一切都是在后台完成的。