我在通过 selenium webdriver 测试 Chrome 时遇到了一个非常奇怪的行为。
与人们期望的导航到页面不同,“get”命令只会导致从目标站点下载小文件(无类型或 .apsx 文件)。
重要的是 - 只有当我将 chrome_options
作为参数传递时才会发生此行为
到 Chrome 驱动程序。
相同的测试脚本可以完美地与 firefox 驱动程序配合使用。
代码:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options # tried with and without
proxy = '127.0.0.1:9951' # connects to a proxy application
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % proxy)
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('whatismyip.com')
导致自动下载名为 download 的文件(无文件扩展名,大小为 2 字节)。 调用其他站点时会导致下载小的 aspx 文件。 这一切都发生在浏览器页面保持空白并且没有与 元素发生 = 网站根本没有加载。
除了抛出 element not found
外,没有错误消息。
这真的很奇怪。
附加信息: 我运行 Debian Wheezy 32 位并使用 Python 2.7。
有什么解决这个问题的建议吗?
最佳答案
我尝试了您的代码并通过 SSH 使用 SOCKS v5 代理捕获了本地主机上的流量。它肯定是通过代理发送数据,但没有数据返回。我已经确认代理正在使用 Firefox 工作。
我在 Ubuntu 14.04 LTS 64 位上运行 Google Chrome。当我尝试在其设置菜单中配置代理时,我的 Chrome 浏览器显示以下消息:
When running Google Chrome under a supported desktop environment, the system proxy settings will be used. However, either your system is not supported or there was a problem launching your system configuration.
But you can still configure via the command line. Please see man google-chrome-stable for more information on flags and environment variables.
很遗憾,我没有 google-chrome-stable 的手册页。
我还发现,根据 selenium 文档,Chrome 正在使用系统范围的代理设置,并且根据他们的文档,不知道如何以编程方式在 Chrome 中设置代理:http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#using-a-proxy
关于python - ChromeDriver 打不开网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27594618/