[英]Error on taking screenshot in Selenium c#
我正在嘗試使用下面的簡單代碼在Selenium 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)
我研究了很多,發現了
這可能是由於我安裝了最新版本的舊Chrome驅動程序版本,但它仍然會出錯
該網站可能無法導航到我通過導航到www.google.com進行檢查的www,但它仍然無效。
我不知道如何解決這個問題。 任何建議都會有所幫助。
我在我的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();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.