Selenium WebDriver with automated Basic Auth credentials

Selenium is a marvelous library for automating browsers. Perl has an interface via Selenium::Remote::Driver. A short script looks like:

use Selenium::Remote::Driver;

my $driver = new Selenium::Remote::Driver;
print $driver->get_title();


Under the assumption that a selenium server is found, this will launch google and print the title. It works very well for a lot of scenarios. One scenario where it has trouble is with Basic Auth and credentials. The browser usually outputs a popup requiring user-input.

This user-input can be automated via OS specific libraries. Under Windows and ActiveState the PerlScript (one word) interface can be utilized to realize a credential entry system.

The code below will launch a browser and then input the credentials for It has been tested on Windows 7, Firefox, Selenium WebDriver 2.0.25, and ActiveState 5.14.2.

use Selenium::Remote::Driver;
use Win32::Process;
use Win32;

$WshArgs = $WScript->{Arguments};
my $password = $WshArgs->Item(0);

if ($password) {
    $WshShell = $WScript->CreateObject(“WScript.Shell”);

    while (1) {
        if ($WshShell->AppActivate(“Authentication Required”)) {




        select(undef, undef, undef, 0.3);


sub ErrorReport{
    $WScript->Echo(Win32::FormatMessage( Win32::GetLastError() ));

my $driver = Selenium::Remote::Driver->new();

my $ProcessObj;
                “start cmd /k cscript keystrokes.pls -password”,
                “.”) || die ErrorReport();





I am not sure if this works for you or not, but I was able to test this ( in Safari 6.0.2 (manually), firefox 15.0.1 using S::R::D all worked. Well I am getting a 404 after authenticating.

Would you mind trying:


Also it looks like there has been a ticket opened for some time now:


I am working on an application which requires Windows authentication. But I am unable to enter the credentials using any method in perl.
I am using perl + Selenium Webdriver.
Further, , this method is also not working in my case.

I am trying the code mentioned in the blog, can you please let me know what will be the values for WshArgs , WScript. what are these variables and from where the value is coming.

Thanks in advance!!!

Leave a comment

About Brian Medley

user-pic I blog about Perl.