selenium C#的屏幕截图,Internet Explorer vs.Chrome供Forge使用,
我使用上述代码在任何浏览器中捕获屏幕截图。我用捕获的图像作为源。我有一个以bmp格式保存的模板图像24BPPRGB。正如您会注意到的,一个RGE只比较24或8个bpp的图像。但是,当IE运行测试时,该文件将以32bppargb格式保存,并且不能在arge上使用。我很高兴听到你对我的问题的建议。请随时问我更多的问题。selenium C#的屏幕截图,Internet Explorer vs.Chrome供Forge使用,,c#,internet-explorer,selenium,screenshot,aforge,C#,Internet Explorer,Selenium,Screenshot,Aforge,我使用上述代码在任何浏览器中捕获屏幕截图。我用捕获的图像作为源。我有一个以bmp格式保存的模板图像24BPPRGB。正如您会注意到的,一个RGE只比较24或8个bpp的图像。但是,当IE运行测试时,该文件将以32bppargb格式保存,并且不能在arge上使用。我很高兴听到你对我的问题的建议。请随时问我更多的问题。 提前谢谢 我使用此功能删除含硒的alpha通道: public static void ScreenShotAndSave(driver, string FileName) {
提前谢谢 我使用此功能删除含硒的alpha通道:
public static void ScreenShotAndSave(driver, string FileName)
{
string userPath = "thePath//image.bmp"
Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();
ss.SaveAsFile(userPath, ImageFormat.Bmp);
}
public static Bitmap RemoveAlphaChannel(Bitmap bitmapSrc) {
Rectangle rect = new Rectangle(0, 0, bitmapSrc.Width, bitmapSrc.Height);
Bitmap bitmapDest = (Bitmap)new Bitmap(bitmapSrc.Width, bitmapSrc.Height, PixelFormat.Format24bppRgb);
BitmapData dataSrc = bitmapSrc.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
BitmapData dataDest = bitmapDest.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
NativeMethods.CopyMemory(dataDest.Scan0, dataSrc.Scan0, (uint)dataSrc.Stride * (uint)dataSrc.Height);
bitmapSrc.UnlockBits(dataSrc);
bitmapDest.UnlockBits(dataDest);
return bitmapDest;
}
static class NativeMethods {
const string KERNEL32 = "Kernel32.dll";
[DllImport(KERNEL32)]
public extern static void CopyMemory(IntPtr dest, IntPtr src, uint length);
}
这是Selenium的一个使用示例:
public static void ScreenShotAndSave(driver, string FileName)
{
string userPath = "thePath//image.bmp"
Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();
ss.SaveAsFile(userPath, ImageFormat.Bmp);
}
public static Bitmap RemoveAlphaChannel(Bitmap bitmapSrc) {
Rectangle rect = new Rectangle(0, 0, bitmapSrc.Width, bitmapSrc.Height);
Bitmap bitmapDest = (Bitmap)new Bitmap(bitmapSrc.Width, bitmapSrc.Height, PixelFormat.Format24bppRgb);
BitmapData dataSrc = bitmapSrc.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
BitmapData dataDest = bitmapDest.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
NativeMethods.CopyMemory(dataDest.Scan0, dataSrc.Scan0, (uint)dataSrc.Stride * (uint)dataSrc.Height);
bitmapSrc.UnlockBits(dataSrc);
bitmapDest.UnlockBits(dataDest);
return bitmapDest;
}
static class NativeMethods {
const string KERNEL32 = "Kernel32.dll";
[DllImport(KERNEL32)]
public extern static void CopyMemory(IntPtr dest, IntPtr src, uint length);
}
你用了什么库?@sara我用的是System.Drawing.Imaging和OpenQA.SeleniumThank,它刚刚解决了我的问题。一旦我获得15个声誉,我会选择这个作为最佳答案!