Selenium IFrame ScreenShot

时间:2016-01-13 19:25:31

标签: java c#

如何做IFrame元素的截图? 我使用这段代码:

public static void SaveScreenShot(IWebDriver driver, IWebElement element)
{
    // Take ScreenCap of Entire Screen
    var screenshotDriver = driver as ITakesScreenshot;
    Screenshot screenshot = screenshotDriver.GetScreenshot();
    var bmpScreen = new Bitmap(new MemoryStream(screenshot.AsByteArray));
    // Crop ScreenCap to Element
    var cropArea = new Rectangle(element.Location, element.Size);
    Bitmap bmpCrop = bmpScreen.Clone(cropArea, bmpScreen.PixelFormat);
    //Save
    bmpCrop.Save("D://img//screen.jpeg", ImageFormat.Jpeg);
}

但它抓住了元素背后的屏幕,所以主页面,而不是iFrame。在做截图之前,我切换到框架:

driver.SwitchTo().Frame(puzzleFrame);

0 个答案:

没有答案