I have a Perl script that uses Selenium to fetch a HTML document called foo that doesn’t exist (404 not found.) The default behavior is for the script to print an error and terminate, such that “bar” is never printed. I’m looking for a way to get it to continue on instead, such that “bar” is printed.
Here’s what I’ve got. Code (called foo.pl):
#!/usr/bin/perl
use strict;
use WWW::Selenium;
my $sel = WWW::Selenium->new( host => "localhost",
port => 4444,
browser => "*chrome",
browser_url => "http://www.google.com/" );
$sel->start;
$sel->open("http://www.google.com/foo.html")
print "bar";
Here’s the message that is printed:
Error requesting http://localhost:4444/selenium-server/driver/?cmd=open&1=http%3A%2F%2Fwww.google.com%2Ffoo.html&sessionId=bc9c086eef804a7c8a0090674333e4c7:
XHR ERROR: URL = http://www.google.com/foo.html Response_Code = 404 Error_Message = Not Found
I’ve looked all over, but haven’t found an answer to this. Thanks!
I’m not sure of the implementation in Perl, but in Java, Selenium-RC has a traffic capture mode, defined as
selenium.start("captureNetworkTraffic=true");that will enable you to capture HTTP responses, including error codes. Once the error code is retrieved, you can always resume execution…Here is an excellent resource on how to capture and process/format this information once retrieved. It uses Python, though, but should give you a start.