如何在不连接到互联网的情况下使用 WebDriverManager 执行自动化脚本? C#

How to execute automation script using WebDriverManager without connecting to the internet? C#

当我尝试 运行 自动化脚本而不连接到互联网时,将返回以下异常:

System.Net.WebException: '无法解析远程名称:'chromedriver.storage.googleapis.com''

有没有什么方法可以在不连接到互联网(离线)的情况下,通过使用特定的 chrome 版本或在 WebDriverManager 中兑现的版本来执行脚本?

enter image description here

enter image description here

从以下位置下载 chromedriver: https://sites.google.com/chromium.org/driver/

下载所需文件后,将 zip 解压缩到计算机上的本地驱动器。

确保将路径添加到提取 chromedriver.exe

的位置
IWebDriver chromeDriver = new ChromeDriver(@ "D:\Download\chromedriver"); //<-Add your path

driver.NetworkConditions = new ChromeNetworkConditions() {
  IsOffline = true, DownloadThroughput = 5000, UploadThroughput = 5000, Latency = TimeSpan.FromMilliseconds(5)
};

driver.Navigate().GoToUrl("https://chris.bolin.co/offline/");

Note: You could also create an environment variable named webdriver.chrome.driver on your machine that's value is the path to where the local chromedriver.exe is located. If you set up a webdriver.chrome.driver variable you would not have to pass the chrome driver argument when you create a ChromeDriver instance