首页 > 解决方案 > 硒进行的访问没有出现

问题描述

我正在尝试使用以下设置在 localhost 站点上进行自动化测试:

Python 3.8.10
selenium 3.141.0
Firefox 90.0
Burp Suite 社区版 v2021.6.2

我正在使用地址为 127.0.0.1:8080 的 Burp 代理。

我在这里测试了几个可用的示例。下面的代码是迄今为止效果最好的代码。

from selenium import webdriver

firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True

PROXY = "127.0.0.1:8080"

firefox_capabilities['proxy'] = {
    "proxyType": "MANUAL",
    "httpProxy": PROXY,
    "sslProxy": PROXY
}

driver = webdriver.Firefox(capabilities=firefox_capabilities)
driver.get("http://127.0.0.1")

当 driver.get("URL here") 中的 url 不是 localhost 时,此代码可以正常工作。当我输入 url http://127.0.0.1时,selenium 进行的访问不会出现在 Burp Suite 的 HTTP 历史记录中。代替访问的 url,出现“http://detectportal.firefox.com”。

这是代码中的问题还是我需要做的一些配置?

打嗝 HTTP 历史

标签: selenium-webdriverfirefoxburp

解决方案


查看 Firefox 代理设置,您可以在那里找到 localhost 连接永远不会定向到代理的声明。

但这可以通过打开about:config并将选项设置为network.proxy.allow_hijacking_localhost来更改true


推荐阅读