8

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?

Guy
  • 14,178
  • 27
  • 67
  • 88

2 Answers2

5

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

Guy
  • 14,178
  • 27
  • 67
  • 88
1

Start the browser in "proxy-injection mode" (note *pifirefox instead of *firefox). Then you can call the captureNetworkTraffic method.

import selenium
import time

sel=selenium.selenium("localhost",4444,"*pifirefox","http://www.google.com/webhp") 
sel.start()
time.sleep(1)
print(sel.captureNetworkTraffic('json'))

I learned the *pifirefox "trick" here.

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
  • But does this method work without starting the driver with "captureNetworkTraffic=true"? Meaning unlike Java, etc. this method or feature in Python will be "always on"? – David Sep 28 '11 at 06:05
  • @David: Instead of `captureNetworkTraffic=true`, I found I needed to start the browser in proxy injection mode. (see above) – unutbu Sep 28 '11 at 09:39