Is it possible to Capture POST data in Selenium?

post, selenium

Solution

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()

Problem

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.

Original source