Reputation: 11
I'm trying to capture http request parameters using Selenium::Remote::Driverand Browsermob::Proxy. The pseudo code is as below. I couldn't get the http headers.
Any help would be appreciated.
use Selenium::Remote::Driver;
use Data::Dumper;
my $proxy = Browsermob::Proxy->new(trace => 2);
my $driver = Selenium::Remote::Driver->new(
browser_name => 'firefox',
proxy => $proxy->selenium_proxy(1)
);
$proxy->new_har( payload => {
initialPageRef => '1' }, captureHeaders => 'true',
captureContent => 'true',
captureBinaryContent => 'true');
$driver->get('http://www.google.com/');
print Dumper($proxy->har);
UPDATE:
However, I could capture only first request. The subsequent requests that selenium drive makes couldn't be captured. For example, the below code captures only the first GET request not the second one.
use Data::Dumper;
use Browsermob::Proxy;
use Selenium::Remote::Driver;
my $proxy = Browsermob::Proxy->new(
server_port => 8080,
);
$proxy->new_har( payload => {
initialPageRef => 'payload is optional' }, captureHeaders => 'true',
captureContent => 'true',
captureBinaryContent => 'true', port => $proxy->port );
my $driver = Selenium::Remote::Driver->new(
browser_name => 'firefox',
proxy => { 'proxyType' => 'manual', 'httpProxy' => '127.0.0.1:'.$proxy->port},
);
$driver->get('http://www.google.com/');
$driver->find_element("//input[\@name='q']")->send_keys("selenium");
$driver->find_element("//button[\@name='btnG']")->click;
print Dumper($proxy->har);
Upvotes: 1
Views: 1674
Reputation: 21666
Use create_new_har
instead of new_har
.
$proxy->create_new_har(
payload => {
initialPageRef => 'payload is optional'
},
captureHeaders => 'true',
captureContent => 'true',
captureBinaryContent => 'true'
);
Upvotes: 0