Take the 2-minute tour ×

I wrote a simple perl script with the WWW::Selenium module that interacts with the Selenium RC server and goes to a webpage and downloads the source. I am able to do this with HTML pages. However, I have an XML page I want to download the source of. This is obviously not possible with the 'get_source_html()' function. Below is the script of what i want to do:

#!/usr/bin/perl -sw
use WWW::Selenium;

print "\n setting up Selenium...\n";
port => 4444,
browser => "*firefox",
browser_url => "http://www.google.com",

print " starting Selenium...\n";


my $xml = $sel->get_html_source();
print $xml;

As you can see the get_html_source is obviously a problem since it will return an error saying that the page is not html. Is there some way that I can just download the current page visible in the browser regardless of the type of page(like the click 'view source' in firefox or even better: some get_source() function)? Also note, that the url I need to use does not end in something like a '.xml' file. The page is generated on the fly if that means anything...

Any wisdom greatly appreciated!

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

You want the Selenium RC get_page_source() function. It works even if the "page" isn't HTML (even plain text, not just XML).

share|improve this answer
yep, get_page_source() solved my issues! :) –  CODEBLACK Sep 12 '12 at 6:46
add comment

The Selenium::Remote::Driver Perl module does offer a get_page_source function.

On the other hand, WWW::Selenium does not provide such a method. It only offers a get_html_source function which returns the entire HTML source between the opening and closing "html" tags.

However, a workaround to get the content of an XML document through WWW::Selenium is to use its get_eval function in order to evaluate a JavaScript snippet that will do the job instead. For example, the following line returns the XML contents of the root node/element of the document contained in the browser window:

my $xml = $sel->get_eval("new XMLSerializer().serializeToString(window.document.documentElement)");
share|improve this answer
add comment

try with:

share|improve this answer
thx for the response! Unfortunately, this (stubbornly) does not want to work for me. I found a workaround with the module Selenium::Remote::Driver. Its get_page_source() function was able to do it for me. –  CODEBLACK Sep 8 '12 at 7:33
This doesn't work because an XML file doesn't have a <BODY> tag. –  Ross Patterson Sep 11 '12 at 23:52
add comment

Your Answer


