Selenium webdriver 屏幕截图不适用于chrome浏览器,但同样的代码适用于firefox

Selenium webdriver 屏幕截图不适用于chrome浏览器,但同样的代码适用于firefox,selenium-webdriver,screenshot,Selenium Webdriver,Screenshot,此代码在Firefox浏览器上运行正常,但在Chrome浏览器上出现以下错误。 **CaptureScreenShot.java** public class CaptureScreenshot { WebDriver driver; public static void takescreenshot(WebDriver driver,String Screenshotname) throws IOException {

此代码在Firefox浏览器上运行正常,但在Chrome浏览器上出现以下错误。

**CaptureScreenShot.java**

public class CaptureScreenshot {
    WebDriver driver;

          public static void takescreenshot(WebDriver driver,String Screenshotname) throws IOException
           {
                  TakesScreenshot takescreenshot=(TakesScreenshot)driver;
                  File source=takescreenshot.getScreenshotAs(OutputType.FILE);
                  FileUtils.copyFile(source, new File("./Screenshots/"+Screenshotname+".png"));
                  System.out.println("Screenshot Taken Successfully!!!!");

           }

**Main.java**
public class ToadsLogin extends SuperTestNG {



@BeforeClass
    public void precondition()
    {
        System.setProperty("webdriver.chrome.driver", "D:/personal/chromedriver_win32/chromedriver.exe");
        driver=new ChromeDriver();
        driver.get("http://10.1.19.234:8002/");
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

    }
    @Test()
    public void login1()
    {

        Login login=new Login(driver);
        login.toadsLogin();
        //login.clkUsers();
        Assert.assertEquals("Index - TOADSw", "Index - TOADS");
    }

    @AfterMethod
    public void failedCondi(ITestResult result) throws Exception
    {
        System.out.println("Testcase status is"+ result.getStatus());
        System.out.println("result status is"+ ITestResult.FAILURE);
        if(ITestResult.FAILURE==result.getStatus())
        {
            CaptureScreenshot.takescreenshot(driver, "titlefail");
        }

    }

}

我认为Chrome仍然不完全支持使用web驱动程序截图。请看一下Chromedriver项目的未决问题:


您是否尝试更新到最新的chromedriver版本?我已经更新了chrome驱动程序,现在可以使用了……但它只截取了半页屏幕。是否有办法只截取失败的测试用例屏幕截图确保您正确设置了webdriver的窗口大小
Error: FAILED CONFIGURATION: @AfterMethod failedCondi([TestResult name=login1 status=FAILURE method=ToadsLogin.login1()[pri:0, instance:script.ToadsLogin@523884b2] output={null}])
org.openqa.selenium.WebDriverException: unknown error: cannot get automation extension
from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html
  (Session info: chrome=57.0.2987.110)
  (Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information)