如何使用 Chrome 在 Windows 10 和 运行 Selenium 测试上安装 Chrome 驱动程序?

How do I install ChromeDriver on Windows 10 and run Selenium tests with Chrome?

我们有一个 Ubuntu 服务器,用于 运行ning Selenium 测试 Chrome 和 Firefox(我安装了 Chrome 驱动程序),我还想 运行 在我的 Windows 10 计算机上进行本地测试。我想让两台计算机的 Python 代码保持相同。但是我没有找到如何在 Windows 10 上安装 Chrome 驱动程序?我没有在文档中找到它 [1, 2]

这是运行在Chrome中进行测试的代码:

import unittest
from selenium import webdriver

class BaseSeleniumTestCase(unittest.TestCase):
    ...
    ...
    ...
    ...

    def start_selenium_webdriver(self, chrome_options=None):
        ...
        self.driver = webdriver.Chrome(chrome_options=chrome_options)
        ...

我也找到了How to run Selenium WebDriver test cases in Chrome?但是好像没有在Python里面(没有标记编程语言,是什么?)

更新 #1: 我在 https://sites.google.com/a/chromium.org/chromedriver/getting-started 中找到了一些 Python 代码,但是我应该把文件放在 Windows 中的什么位置 10 如果我想为两台计算机保留相同的 Python 代码吗?

更新 #2: 我下载了 chromedriver.exe 并将其放入 C:\Windows 并且它有效,但我没有在任何地方看到它的记录。

正如 Uri 在问题中所述,在 Update #2 下,下载最新版本的 chromedriver 并将其放在 C:\Windows 中可以解决问题。

当浏览器 window 打开时(以及命令提示符 window),我遇到了 Chrome 挂起的相同问题。

可在以下位置找到最新的驱动程序:

https://sites.google.com/a/chromium.org/chromedriver/downloads

chromedriver_win32.zip 文件中的版本适用于我的 64 位系统。

我先简单介绍一下要求吧。 您需要从此处下载 chrome 网络驱动程序压缩包。 https://chromedriver.storage.googleapis.com/index.html?path=2.33/

提取文件并将其存储在所需位置。

在 Eclipse 中创建一个新项目并在您的 class.

中包含以下代码
System.setProperty("webdriver.chrome.driver", "C:\temp\chromedriver.exe");
WebDriver driver = new ChromeDriver();

解释:System.setProperty(key,value)

密钥是所有系统的默认值和相同值,值是您的 chrome 驱动程序提取文件的位置。

  1. 下载 chromedriver.exe 并将其保存到所需位置
  2. executable_path 指定为其保存的路径

示例代码如下:

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('headless')
driver = webdriver.Chrome(executable_path="path/to/chromedriver.exe", chrome_options=options)
driver.get("example.html")
# do something here...
driver.close()

正如 Uri 在问题更新 #2 中所述,如果我们将 chromedriver.exe 放在 C:/Windows 下,则无需指定 executable_path,因为 Python将在 C:/Windows.

下搜索