【问题标题】:ChromeDriver Does Not Open WebsitesChromeDriver 无法打开网站
【发布时间】:2015-02-20 01:49:20
【问题描述】:

我在通过 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')

导致自动下载名为下载的文件(无文件扩展名,大小为 2 字节)。 调用其他站点会导致下载小的 aspx 文件。 这一切都发生在浏览器页面保持空白并且没有与 元素发生 = 网站根本没有加载。

没有错误消息,除了element not found 被抛出。

这真的很奇怪。

附加信息: 我运行 Debian Wheezy 32 位并使用 Python 2.7。

有什么建议可以解决这个问题吗?

【问题讨论】:

  • 你试过http://www.whatismyip.com吗?
  • 谢谢,乔纳森。是的。同样的结果。只有当我放入 chrome_options 时,问题才会出现。我不确定要改用 Desired Capabilities,因为它已被弃用并且据说不能与 ChromeDriver 完美配合。
  • 您的import 是什么样的? @JohnSlathon
  • 谢谢。我已经相应地编辑了我的帖子。我尝试了有无显式导入 Chrome 选项子模块。每次相应地更改较低的语句(webdriver.ChromeOptions() 或 Options())
  • 打败我,对不起@JohnSlathon

标签: python google-chrome selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

我尝试了您的代码并使用 SOCKS v5 代理通过 SSH 捕获了本地主机上的流量。它肯定是通过代理发送数据,但没有数据返回。我已确认代理正在使用 Firefox。

我在 Ubuntu 14.04 LTS 64 位上运行 Google Chrome。当我尝试在其设置菜单中配置代理时,我的 Chrome 浏览器会显示以下消息:

在受支持的桌面环境下运行 Google Chrome 时, 将使用系统代理设置。但是,要么你的系统不是 支持或启动您的系统配置时出现问题。

但您仍然可以通过命令行进行配置。请见人 google-chrome-stable 以获取有关标志和环境的更多信息 变量。

很遗憾,我没有 google-chrome-stable 的手册页。

我还发现,根据 selenium 文档,Chrome 正在使用系统范围的代理设置,根据他们的文档,不知道如何以编程方式在 Chrome 中设置代理:http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#using-a-proxy

【讨论】:

    猜你喜欢
    • 2013-12-18
    • 1970-01-01
    • 2013-09-11
    • 1970-01-01
    • 1970-01-01
    • 2021-04-27
    • 2020-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多