QTP 如何保存网页中的图像

发布于 2024-11-28 13:58:15 字数 163 浏览 5 评论 0原文

我想知道是否可以模拟该过程:右键单击图像 ->单击弹出菜单上的“将图像另存为..”->将图像保存到本地。

我尝试了CaptureBitmap()函数,但结果只是QTP截取的屏幕截图,而不是与上述过程获得的相同图像文件。

还有其他方法吗?非常感谢。

艾伦

I would like to know if it's possible to simulate the process: Right click on an image -> Click on "Save image as.." on the popup menu -> save the image in local.

I tried CaptureBitmap() function, but the result is just a screenshot taken by QTP, not the same image file obtained as the procedure above.

Are there other ways? Many thanks in advance.

Allen

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

噩梦成真你也成魔 2024-12-05 13:58:15

我想这取决于你想做什么。如果您想比较位图,那么CaptureBitmap选项应该可以工作。如果您想比较图像的路径,可以使用Image("x").GetROProperty("src")

如果您确实想保存 src 图像文件,那么不幸的是 QTP 不提供与浏览器上下文菜单交互的方法。您可以尝试使用某些第三方机制从 src URL 下载图像(例如 wget)。


编辑:我只是有另一个想法,我不在工作,所以我无法验证它是否有效,但我很确定它会有效。

首先导致上下文菜单出现,为此,您必须将重播模式更改为设备并运行 RightClick 操作。

 replayType = Setting.WebPackage("ReplayType") ' Store old replay mode
 Setting.WebPackage("ReplayType") = 2 ' change to device replay mode
 Browser("b").Page("p").Image("I").RightClick
 Setting.WebPackage("ReplayType") = replayType ' Revert to old mode

然后将字母 v 发送到浏览器,浏览器将通过使用 设备重播对象

Set deviceReplay = CreateObject( “Mercury.DeviceReplay” )
deviceReplay.SendString "v"

现在,像普通 Win32 控件一样与保存对话框进行交互。

寓意:如果你足够努力,永远不要低估 QTP 能让你做的事情

I suppose it depends what you want to do. If you want to compare the bitmap then the CaptureBitmap options should work. If you want to compare the path to the image you can use Image("x").GetROProperty("src").

If you really want to save the src image file then unfortunately QTP doesn't supply a way to interact with the browser's context menu. You can try to use some third-party mechanism to download the image from the src URL (e.g. wget).


Edit: I just had another thought, I'm not at work so I can't verify that it will work but I'm pretty sure it will.

First cause the context menu to appear, in order to do this you have to change the replay mode to device and run a RightClick operation.

 replayType = Setting.WebPackage("ReplayType") ' Store old replay mode
 Setting.WebPackage("ReplayType") = 2 ' change to device replay mode
 Browser("b").Page("p").Image("I").RightClick
 Setting.WebPackage("ReplayType") = replayType ' Revert to old mode

Then send the letter v to the browser which will select the Save menu item (on both IE and Firefox) by using the device replay object

Set deviceReplay = CreateObject( “Mercury.DeviceReplay” )
deviceReplay.SendString "v"

Now interact with the save dialog as a usual Win32 control.

Moral: Never underestimate what QTP will let you do if you try hard enough

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文