NAME
Win32::CaptureIE - Capture web pages or its elements rendered by Internet Explorer
SYNOPSIS
use Win32::CaptureIE;
StartIE;
Navigate('http://my.server/page.html');
my $img = CaptureElement('tab_user_options');
$img->Write("ie-elem.png");
QuitIE;
DESCRIPTION
The package enables you to automatically create screenshots of your web server pages for the user guide or whatever you need it for. The best part is that you don't bother yourself with scrolling and object localization. Just tell the ID of the element and receive an Image::Magick object. The package will do all the scrolling work, it will take the screenshots and glue the parts together.
EXPORT
- :default
-
CaptureArea
CaptureBrowser
CaptureElement
CaptureElements
CapturePage
CaptureRows
CaptureThumbshot
GetDoc
GetAll
GetElement
Navigate
QuitIE
Refresh
StartIE
$Body
$CaptureBorder
$Doc
$HWND_Browser
$HWND_IE
$IE
Internet Explorer controlling functions
- StartIE ( %params )
-
This function creates a new Internet Explorer process via Win32::OLE. You can specify width and height of the window as parameters.
StartIE( width => 808, height => 600 );
The function will bring the window to the top and try to locate the child window where the page is rendered. The mouse cursor will be moved to the top left corner of the screen to not interfere with the browser.
- QuitIE ( )
-
Terminates the Internet Explorer process and destroys the Win32::OLE object. Restores the original cursor position.
-
Loads the specified page and waits until the page is completely loaded. Then it will call
GetDoc
function. - Refresh ( )
-
Refreshes the currently loaded page and calls
GetDoc
function. - GetDoc ( )
-
Loads
$Doc
and$Body
global variables. - GetAll ( $tagName [, $index ] )
-
Returns the list of objects of specified tag name or N-th object from the list if $index is specified. The first element in the list has indx 0. The list is composed from
document->all
collection. - GetElement ( $id )
-
Returns the object of specified ID by calling
document->getElementById()
.
Capturing functions
These function works like other Capture*(...)
functions from Win32::Screenshot package.
- CaptureArea ( $px, $py, $w, $h )
-
Capture selected area on page. The coordinates are relative to the tole left corner of the page. If the area is larger than the window the function will capture the whole area step by step by scrolling the window content (in all directions) and will return a complete image of the page.
- CaptureBrowser ( )
-
Captures whole Internet Explorer window including the window title and border.
- CaptureElement ( $id | $element [, \%args ] )
-
Captures the element specified by its ID or passed as reference to the element object. The function will scroll the page content to show the top of the element and scroll down and right step by step to get whole area occupied by the object.
It can capture a small surrounding area around the element specified by %args hash or
$CaptureBorder
global variable. It recognizes paramtersborder
,border-left
,border-top
,border-right
andborder-bottom
. The priority isborder-*
->border
->$CaptureBorder
. - CaptureElements ( $id1 | $element1, $id2 | $element2, ... [, \%args ] )
-
Captures all selected elements. The function captures the outter bounding box of all elements in the same way as CaptureElement captures only one.
- CapturePage ( )
-
Captures whole page currently loaded in the Internet Explorer window. Only the page content will be captured - no window, no scrollbars. If the page is smaller than the window only the occupied part of the window will be captured. If the page is longer (scrollbars are active) the function will capture the whole page step by step by scrolling the window content (in all directions) and will return a complete image of the page.
- CaptureRows ( $id | $element , @rows )
-
Captures the table specified by its ID or passed as reference to the table object. The function will scroll the page content to show the top of the table and scroll down and right step by step to get whole area occupied by the table. Than it will chop unwanted rows from the image and it will return the image of table containing only selected rows. Rows are numbered from zero.
It can capture a small surrounding area around the element specified by
$CaptureBorder
global variable. - CaptureThumbshot ( )
-
Resizes the window to set the client area to 800x600 pixels. Captures the client area where the page is rendered. No scrolling is done.
Global variables
- $CaptureBorder
-
The function
CaptureElement
is able to capture the element and a small area around it. How much of surrounding space will be captured is defined by$CaptureBorder
. It is not recommended to capture more than 3-5 pixels because parts of other elements could be captured as well. Default border is 1 pixel wide. - $IE
-
The function
StartIE
will create a new Internet Explorer process and its Win32::OLE reference will be stored in this variable. See the MSDN documentation for InternetExplorer object. - $Doc
-
The function
GetDoc
will assign$IE->{Document}
into this variable. See the MSDN documentation for Document object. - $Body
-
The function
GetDoc
will assign$IE->{Document}->{Body}
into this variable. See the MSDN documentation for BODY object. - $HWND_IE
-
The function
StartIE
will assign the handle of the Internet Explorer window into this variable from$IE->{HWND}
. - $HWND_Browser
-
The function
StartIE
will try to find the largest child window and suppose that this is the area where is the page rendered. It is used to convert page coordinates to screen coordinates.
TIPS
- Calling JavaScript functions
-
If you need to call a JavaScript function to get to anoter page or submit the form you can just use Navigate. Note that
Win32::CaptureIE::Navigate()
waits for page load complete but$IE->Navigate()
do not.Navigate("javascript:form_submit('approve');");
- Capturing only a part of element
-
To capture only a part of the element set the border to negative values. But do not overdraw it, you still have to have something to capture.
# capture messages between the toolbar and the 1st fieldset $img = CaptureElements('toolbar', GetAll('FIELDSET', 0), { border_top => -12, border_bottom => -64 } );
SEE ALSO
- MSDN
-
http://msdn.microsoft.com/library You can find there the description of InternetExplorer object and DOM.
- Win32::Screenshot
-
This package is used for capturing screenshots. Use its post-processing features for automatic screenshot modification.
AUTHOR
P.Smejkal, <petr.smejkal@seznam.cz>
COPYRIGHT AND LICENSE
Copyright (C) 2004 by P.Smejkal
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available.