繁体   English   中英

如何使用Selenium C#拍摄下拉菜单的屏幕截图?

[英]How to take screenshot of drop-down menu with Selenium C#?

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

我一直在寻找相同的东西,以获取下拉菜单的屏幕截图。 我发现,使用键盘笔触:Alt +向下键可以打开下拉菜单。 可以通过以下方法完成此操作:

//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");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM