Bit*_*ise 3 selenium ruby-on-rails capybara selenium-chromedriver selenium-webdriver
我的 Capybara Selenium Webdriver 设置在尝试连接 ChromeDriver 时失败 - 看来他们发布了一个没有 M1 版本的版本,可以在 Chromedriver API 中找到https://chromedriver.storage.googleapis.com/index.html?path=106.0.5249.61/
Webdrivers::NetworkError:
Net::HTTPServerException: 404 "Not Found" with https://chromedriver.storage.googleapis.com/106.0.5249.61/chromedriver_mac64_m1.zip
Run Code Online (Sandbox Code Playgroud)
Capybara.register_driver :headless_chrome do |app|
options.add_argument("--disable-gpu")
options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument("--window-size=1920,1080")
driver = Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
### Allow file downloads in Google Chrome when headless
### https://bugs.chromium.org/p/chromium/issues/detail?id=696481#c89
bridge = driver.browser.send(:bridge)
path = "/session/:session_id/chromium/send_command"
path[":session_id"] = bridge.session_id
bridge.http.call(:post, path, cmd: "Page.setDownloadBehavior",
params: {
behavior: "allow",
downloadPath: "/tmp/downloads",
})
###
driver
end
Run Code Online (Sandbox Code Playgroud)
当应用程序调用时,driver.browser我收到上述错误,这是因为它正在查找的文件不存在。
我可以设置特定版本的 chrome 驱动程序或在初始化驱动程序时查找什么系统吗?
我有一台苹果硅 Mac,但仍然有旧的(英特尔)chromedriver。为了解决这个问题,我必须:
\n您可能只需要执行第二步,具体取决于您是否已经安装了Apple Silicon chromedriver。检查方法见下文。
\n运行这两个命令,如果输出如下所示,则说明您已安装 Apple Silicon chromedriver,并且可以跳到更新 webdrivers gem:
\nwhich chromedriver\n# /opt/homebrew/bin/chromedriver\n\nfile $(which chromedriver)\n# /opt/homebrew/bin/chromedriver: Mach-O 64-bit executable arm64\nRun Code Online (Sandbox Code Playgroud)\n但如果输出是这样的,则说明您仍然拥有 intel 版本的 chromedriver,并且需要更新到 Apple Silicon 版本:
\nwhich chromedriver\n# /usr/local/bin/chromedriver\n\nfile $(which chromedriver)\n# /usr/local/bin/pandoc: Mach-O 64-bit executable x86_64\nRun Code Online (Sandbox Code Playgroud)\n要安装Apple Silicon chromedriver:
\nbrew install --cask chromedriver\nRun Code Online (Sandbox Code Playgroud)\n在新的终端窗口中运行which chromedriver并file $(which chromedriver)再次检查它现在显示苹果硅(ARM)版本。
如果您收到来自 Apple 的错误:
\n\n\n\xe2\x80\x9cchromedriver\xe2\x80\x9d 无法打开\xe2\x80\x99,因为 Apple 无法检查它是否存在恶意软件。
\n
只需运行此命令并重试:
\nwhich chromedriver\n# /usr/local/bin/chromedriver\n\nfile $(which chromedriver)\n# /usr/local/bin/pandoc: Mach-O 64-bit executable x86_64\nRun Code Online (Sandbox Code Playgroud)\nwebdrivers gem必须 >= 5.2.0,以便它知道在哪里寻找 Apple Silicon chromedriver。
\n在我的 Gemfile 中是这样的:
\ngem "webdrivers"\nRun Code Online (Sandbox Code Playgroud)\n所以我把它改为:
\ngem "webdrivers", "~> 5.2.0"\nRun Code Online (Sandbox Code Playgroud)\n捆绑安装,一切正常。
\n| 归档时间: |
|
| 查看次数: |
3144 次 |
| 最近记录: |