I've found many tutorials for selenium in java in which you first start selenium using s.start("captureNetworkTraffic=True")
, but in python start()
does not take any arguments.
How do you pass this argument? Or don't you need it in python?
I've found many tutorials for selenium in java in which you first start selenium using s.start("captureNetworkTraffic=True")
, but in python start()
does not take any arguments.
How do you pass this argument? Or don't you need it in python?
Looking inside selenium.py, I found that
the selenium.selenium
class has a captureNetworkTraffic
method:
Definition: sel.captureNetworkTraffic(self, type)
Docstring: Returns the network traffic seen by the browser, including headers, AJAX requests, status codes, and timings. When this function is called, the traffic log is cleared, so the returned content is only the traffic seen since the last call.
'type' is The type of data to return the network traffic as. Valid values are: json, xml, or plain.
I changed the start
in selenium.py
:
def start(self, captureNetworkTraffic=False):
l = [self.browserStartCommand, self.browserURL, self.extensionJs]
if captureNetworkTraffic:
l.append("captureNetworkTraffic=true")
result = self.get_string("getNewBrowserSession", l)
The you do:
sel = selenium.selenium('localhost', 4444, '*firefox', 'http://www.google.com')
sel.start(True)
sel.open('')
print sel.captureNetworkTraffic('json')
and it works like a charm