Selenium 打开浏览器但不加载页面

Selenium opens browser but doesn't load page

这是 a previous post 的扩展,我无法开始工作,但我现在在更新 Selenium 后收到新错误。

我正在使用 Python 3.5、Windows 8.1 和 Selenium 3.0.1。

我知道代码可以工作,因为它可以在我的 Mac 上工作,但是当我把它带到我的工作计算机上时(如上所述),唯一发生的事情是浏览器会打开,但它赢了'加载任何内容,甚至是主页。

根据我在搜索中找到的所有内容,我下载了 geckodriver,将其重命名为 wires.exe,并将目录添加到系统 PATH 环境变量。

我完全不知道该怎么做才能让它发挥作用。这是我正在使用的代码:

from selenium import webdriver

driver = webdriver.Firefox()

driver.get('https://www.google.com')

我没有将 geckodriver 添加到 PATH(它位于与 Python 脚本相同的目录中),并且在 Selenium 更新到 3.0.1 后,使用此代码启动 Selenium 会话:

gecko = os.path.normpath(os.path.join(os.path.dirname(__file__), 'geckodriver'))
binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary, executable_path=gecko+'.exe')

另外:您需要将 geckodriver 更新到最新版本 0.11.1。

您需要设置可执行文件 geckodriver 的完整路径,如下所述:

self.driver = webdriver.Firefox(executable_path = 'D:\Selenium_RiponAlWasim\geckodriver-v0.18.0-win64\geckodriver.exe')

下载geckodriver适合你的OS→解压到你选择的文件夹→正确设置路径。

我正在使用 Python 3.6.2 和 Selenium WebDriver 3.4.3。

对于Windows 10,下载gechodriver。并像下面一样提取它。为自己定制。我的用户名是 yasin Windows 10.

C:\Users\yasin\AppData\Local\Programs\Python\Python37\Scripts

对于 Mac 用户:此问题(以及 Notarization issues with geckodriver) can be avoided by installing the software via Homebrew

我的 Ubuntu 20.10 (Groovy Gorilla) 安装遇到了同样的问题,并使用以下行在终端上修复了它:

sudo apt-get install firefox-geckodriver

你可以用 macOS 机器做同样的事情:

brew install geckodriver