简体   繁体   English

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

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

I am new to Selenium and to C#. 我是Selenium和C#的新手。 I am trying to create an automation code to a website and saving screenshots of the elements of each step. 我正在尝试为网站创建一个自动化代码,并保存每个步骤的元素的屏幕截图。 Figured a way to save screenshots only of specified elements, however the drop-down menus are not appearing on the saved images. 想出了一种仅保存指定元素的屏幕截图的方法,但是下拉菜单没有出现在保存的图像上。 Tried using the PRTSC option which is doing the job but taking images only of the screen and I only need image of the drop-down menu and not the whole page. 使用PRTSC选项进行了尝试,该选项可以完成工作,但仅拍摄屏幕图像,我只需要下拉菜单的图像,而不需要整个页面的图像。 Is there a way in Selenium that I can take screenshot only of the drop-down list? Selenium中有什么方法可以仅对下拉列表进行屏幕截图? Any idea or advice is welcome. 欢迎任何想法或建议。

I was looking for the same, to have screenshots of dropdowns. 我一直在寻找相同的东西,以获取下拉菜单的屏幕截图。 I figured that, on using the keyboard strokes: Alt+Down arrow we can open the dropdown. 我发现,使用键盘笔触:Alt +向下键可以打开下拉菜单。 The same can be done by below: 可以通过以下方法完成此操作:

//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