allenzzzxd
allenzzzxd

Reputation: 331

QTP How to save images from webpages

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

Upvotes: 2

Views: 2520

Answers (1)

Motti
Motti

Reputation: 114725

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

Upvotes: 3

Related Questions