gpt4 book ai didi

c# - 鼠标交互未显示在 webdriver 屏幕截图中

转载 作者:太空狗 更新时间:2023-10-29 20:41:54 24 4
gpt4 key购买 nike

我目前使用的是 Selenium WebDriver 2.35,但在截取屏幕截图时遇到了障碍。我编写了一个接受 IWebElement 并将返回特定元素的屏幕截图的小函数。我试图截图的元素实际上是从 Sprite 中提取的图像。虽然这个元素很棘手,因为在鼠标悬停/悬停时图像从灰色变为其真实颜色(通过移动到 Sprite 的不同部分)。我能够通过此功能获得图像的正确屏幕截图,但无法让它识别与 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;
}

最佳答案

根据我的经验,使用通过 Selenium Grid 路由的自动化,看不到鼠标。也许这是因为“鼠标”实际上是一个虚拟的 Selenium 鼠标,并且未连接到系统 native 鼠标驱动程序。

关于c# - 鼠标交互未显示在 webdriver 屏幕截图中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18790744/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com