是否可以在Selenium中捕获POST数据? [英] Is it possible to Capture POST data in Selenium?
问题描述
我正在使用 Selenium WebDriver工具,想知道该工具是否提供了一种捕获生成的POST数据的方法提交表格时.我正在使用django测试框架来测试我的数据是否在后端正确处理,我想使用Selenium来验证表单是否生成了预期的数据.
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.
推荐答案
您将不得不在中间放置一个代理并监视该代理.您可以使用 http://pypi.python.org/pypi/browsermob-proxy .允许您将代理详细信息传递到WebDriver,然后可以拉出显示所有网络流量的HAR文件.
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.
您还可以使用 HARPy 来获取所需的信息
You can also use HARPy to then get the info you want
BrowserMob代理和硒的示例
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()
这篇关于是否可以在Selenium中捕获POST数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!