I'm working with the Selenium WebDriver Tool and am wondering if this tool provides a means for capturing the POST data generated when submitting a form. I'm using the django test framework to test that my data is processed correctly on the backend, I want to use Selenium to verify that the form produces the expected data.
Asked
Active
Viewed 4,896 times
1 Answers
5
You are going to have to put a proxy in the middle and monitor that proxy. You can use http://pypi.python.org/pypi/browsermob-proxy. that allows you to pass in proxy details to WebDriver and then you can pull out a HAR file which shows all the network traffic.
You can also use HARPy to then get the info you want
Example of BrowserMob Proxy and Selenium
from browsermobproxy import Server
server = Server("path/to/browsermob-proxy")
server.start()
proxy = server.create_proxy()
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)
proxy.new_har("google")
driver.get("http://www.google.co.uk")
proxy.har # returns a HAR JSON blob
proxy.stop()
driver.quit()

AutomatedTester
- 22,188
- 7
- 49
- 62
-
Thanks for the info and suggestions. I see you're a selenium committer. Can you explain to me why Selenium can't capture this data? – mklauber Jun 18 '12 at 19:58
-
WebDriver emulates what a user can do. A user cannot see the packets flowing, only what gets rendered in the browser. This is the same reason why you cannot click an element that is not visible to the user. (Unlike Se-RC which kinda grew to include everything under the sun, including the kitchen sink.) – adam goucher Jun 18 '12 at 20:13
-
Fair enough. Sounds more like a policy than a technical limitation, (choosing not to create that ability) but I can understand the reasoning. Thanks. – mklauber Jun 18 '12 at 21:09