【问题标题】:How to take screenshot of drop-down menu with Selenium C#?如何使用 Selenium C# 截取下拉菜单的屏幕截图?
【发布时间】:2014-01-01 12:05:46
【问题描述】:

我是 Selenium 和 C# 的新手。我正在尝试为网站创建自动化代码并保存每个步骤元素的屏幕截图。 想办法只保存指定元素的屏幕截图,但是下拉菜单没有出现在保存的图像上。 尝试使用 PRTSC 选项,它正在完成这项工作,但只拍摄屏幕图像,我只需要下拉菜单的图像,而不是整个页面。 Selenium 中有没有一种方法可以只截取下拉列表的屏幕截图? 欢迎任何想法或建议。

【问题讨论】:

  • 我想到了两个选项:截取完整的屏幕截图并将其裁剪到页面上的元素,或者获取完整的屏幕截图但仅突出显示所需的元素。

标签: c# selenium html-select


【解决方案1】:

我一直在寻找相同的内容,以获得下拉菜单的屏幕截图。我想,在使用键盘敲击时:Alt+Down arrow 我们可以打开下拉菜单。 同样可以通过以下方式完成:

//Alt key code is 18, the below does the alt key stroke
selenium.KeyDownNative("18");

//Down arrow key code is 40, the below does the downkey stroke
selenium.KeyDownNative("40");

//Takes screenshot
selenium.CaptureScreenshot(@"d:\Image.jpg");

//Release alt key
selenium.KeyUpNative("18");

//Releases down arrow key.
selenium.KeyUpNative("40");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-22
    • 2015-07-07
    • 2016-06-30
    • 2015-11-13
    • 1970-01-01
    • 1970-01-01
    • 2021-08-27
    • 1970-01-01
    相关资源
    最近更新 更多