私は現在 Selenium WebDriver 2.35 を使用していますが、スクリーンショットを撮る際に障害にぶつかっています。IWebElement を受け取り、特定の要素のスクリーンショットを返す小さな関数を作成しました。スクリーンショットを作成しようとしている要素は、実際にはスプライトから取得した画像です。ただし、この要素はトリッキーです。マウスオーバー/ホバーすると、画像がグレーから本来の色に変わるためです(スプライトの別の部分に移動することにより)。この関数を使用して画像の適切なスクリーンショットを取得できますが、ITakesScreenshot とのマウス操作を認識できません。画像がホバーされていることはブラウザーで視覚的に確認できますが、スクリーンショットでは確認できません。何かご意見は?
public static Bitmap GetImage(IWebElement element)
{
RemoteWebDriver driver = BrowserManager.GetInstance().GetDriver();
Actions action = new Actions(driver);
//take screenshot of page
action.MoveToElement(element).Build().Perform();
Byte[] ba= ((ITakesScreenshot)driver).GetScreenshot().AsByteArray;
Bitmap ss = new Bitmap(new MemoryStream(ba));
//ss.Save("c:\\tmp\\ss.png", ImageFormat.Png);
Rectangle crop = new Rectangle(element.Location.X, element.Location.Y, element.Size.Width, element.Size.Height);
//create a new image by cropping the original screenshot
Bitmap image = ss.Clone(crop, ss.PixelFormat);
return image;
}