Selenium and PERL : File handling with AutoIT script.
To handle file download window, develop logic and write code based on following two points.
- First run the AutoIT script as a process.
- Click on Link that downloads file.
When AutoIT script is running as process, it is waiting for new windows pop-up (Windows) event. When selenium code clicks on any link that downloads file, browser opens new pop-up (Windows). When AutoIt script finds new windows with specific title, it takes control and clicks button available on pop-up windows GUI.
How to create process in perl.
- Install PERL module Win32::Process.
- Create exe file of your AutoIt script.
- Assumed AutoIt is already installed on your systemperl script:
use Win32::Process;
# Error handling
sub ErrorReport()
{
Info_Log("Info","Can not create process ","fatal");
print Win32::FormatMessage( Win32::GetLastError() );
}# Create Process.
sub create_process()
{
my ($process, $args) = @_;
### $process= file to be executed as process.
### $args = Arguments to be passed to process.Win32::Process::Create($ProcessObj,
$process,
$args,
0,
NORMAL_PRIORITY_CLASS,
".")|| die &ErrorReport();
return ($ProcessObj);
}
# Download file abce.com for your http server
my %testdata;
my $filetobedowmnload = "abce.com";$testdata{'LinkToClick'} = "http://yourserver.com/abcd/bcd/$filetobedowmnload " ;
# LinkToClick is your link name. You should use link name properly in your code.
# Here I have taken whole path of file on http server. It just for example.
&create_process("Lib\\filedownload.exe","filedownload.exe $filetobedowmnload 1 1");
# Now click on link
&click_link($testdata{'LinkToClick'});# File will be downloaded at default download folder.
#### Rest of the code....
Comments
Post a Comment