错误服用截图中硒C#

问题描述:

我想只要我把这个方法在我的测试代码采取硒C#截图有一个简单的代码下面错误服用截图中硒C#

public void takeScreenshot() 
    { 
     Screenshot screenshot = ((ITakesScreenshot)DriverContext.Driver).GetScreenshot(); 
     screenshot.SaveAsFile(@"C:\images\image.png", ImageFormat.Png); 
    } 

,它抛出的错误:

System.InvalidOperationException: unknown error: cannot get automation extension 
from unknown error: page could not be found: chrome- 
extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html 
(Session info: chrome=58.0.3029.110) 
(Driver info: chromedriver=2.27.440174 
(e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.10586 x86_64) 

我研究了不少,发现

  1. ,这可能是由于旧的镀铬驱动程序版本FO r我安装了最新的一个,但它仍然给出了错误

  2. 该网站可能无法导航到www,我通过导航到www.google.com进行了检查,但它仍然无效。

我不知道如何解决此问题。任何建议都会有所帮助。

+0

添加加载扩展的代码。添加您使用过的库的版本。 –

我在我的TearDown中使用了它,它为我工作 - 也许有什么与DriverContext.Driver在那一点上解决什么?

[TearDown] 
    public void TearDown() 
    { 
     if (TestContext.CurrentContext.Result.Outcome != ResultState.Success) 
     { 
      var screenshot = ((ITakesScreenshot)browser).GetScreenshot(); 
      var filename = TestContext.CurrentContext.Test.MethodName + "_screenshot_" + DateTime.Now.Ticks + ".jpg"; 
      var path = "C:\\Temp\\" + filename; 
      screenshot.SaveAsFile(path , ScreenshotImageFormat.Jpeg); 
      TestContext.AddTestAttachment(path); 
     } 
     browser.Quit(); 
    }