无法使用IE Webdriver在IE9中截取PDF

时间:2014-08-13 10:40:36

标签: internet-explorer pdf selenium webdriver

我可以在Firefox中截取屏幕截图,但无法在IE中获取屏幕截图[获取空白screeshot]

以下是代码。

package com.test;

import java.io.File;
import java.io.IOException;
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.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class PDFScreen {
public static void main(String[] args) throws InterruptedException, IOException {

    String url = "C:\\Users\\XXXXXX\\Desktop\\selenium.pdf";

    /*FireFox*/ //It worked here using this driver
    /*File pathToBinary = new File(
            "C:\\Users\XXXXXX\\AppData\\Local\\Mozilla Firefox\\firefox.exe");

    FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);

    FirefoxProfile firefoxProfile = new FirefoxProfile();

    WebDriver driver = new FirefoxDriver(ffBinary, firefoxProfile);*/


    /*IE Driver*/ //It is not working using this driver
    System.setProperty("webdriver.ie.driver",
            "C:\\swpack\\IEDriverServer_x64_2.42.0\\IEDriverServer.exe");

    DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
    // By default 119% so set to ignoring the zoom part
    caps.setCapability("ignoreZoomSetting", true);

    caps.setCapability(
            InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
            true);

    WebDriver driver = new InternetExplorerDriver(caps);

    driver.get(url);
    //Sleeping so that pdf file gets loaded
    Thread.sleep(3000);
    File screenshot = ((TakesScreenshot) driver)
            .getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(screenshot, new File(
            "C:\\Users\\XXXXXX\\Desktop\\PDF\\1.jpg"));

    driver.quit();
}
}


I cannot use this code,
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Rectangle screenRectangle = new Rectangle(screenSize);
        Robot r = new Robot();
        BufferedImage bufferedImage = r.createScreenCapture(screenRectangle);
        ImageIO.write(bufferedImage, "png", new File("C:\\Users\\XXXXXX\\Desktop\\2.jpg"));

As multiple threads of jobs run parallely in my project so screen shot cannot be taken with this code.

如果有人遇到并解决了这类问题,那么任何人都可以帮助在IE浏览器中搜索PDF文件吗?

0 个答案:

没有答案