gpt4 book ai didi

selenium-webdriver - 无法加载资源:net::ERR_UNKNOWN_URL_SCHEME 使用 capybara 和 headless chrome 渲染 jstree 时

转载 作者:行者123 更新时间:2023-12-04 01:49:26 24 4
gpt4 key购买 nike

最近我在 rspec 测试中切换到 headless chrome。移动之后,我所有与 jstree 元素交互的测试都开始失败。下面是允许重现错误的最小代码:

Gemfile 中有依赖:

# Gemfile
gem 'capybara', '2.18.0'
gem 'selenium-webdriver', '3.141.0'

这是呈现 jstree 的简单页面:

# jstree.html

<!doctype html>
<html>
<head>
<script src="https://rawgit.com/jquery/jquery/1.12.4/dist/jquery.min.js"></script>
<script src="https://rawgit.com/vakata/jstree/3.3.7/dist/jstree.min.js"></script>
<link href="https://rawgit.com/vakata/jstree/3.3.7/dist/themes/default/style.min.css" rel="stylesheet"/>
</head>

<body>
<h1>This is a list:</h1>
<ul id="tree"></ul>
<script>
$('#tree').jstree({
core: {
data: [{ "id": 1, "state": {}, "text": "Example", "parent": "#" }]
}
});
</script>
</body>
</html>

有一个ruby脚本可以用Capybara打开页面并保存页面截图:

# script.rb
require 'capybara'

require 'selenium-webdriver'
Capybara.register_driver :chrome do |app|
options = ::Selenium::WebDriver::Chrome::Options.new(
args: %w[headless no-sandbox disable-dev-shm-usage window-size=1280,800])

Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end

Capybara.default_driver = :chrome
Capybara.app = Rack::File.new File.expand_path('../', __FILE__)

include Capybara::DSL
visit '/jstree.html'
page.save_and_open_screenshot

当我运行 bundle exec ruby​​ script.rb 然后打开屏幕截图时,我看到以下内容:

enter image description here

但是当我在 chrome 浏览器中打开 jstree.html 时,我看到的是普通树:

enter image description here

当我将输出浏览器控制台消息添加到脚本末尾时

puts page.driver.browser.manage.logs.get(type)

然后重新运行 bundle exec ruby​​ script.rb 我明白了

SEVERE 2018-12-27 16:24:23 +0300: blob:http://127.0.0.1:49346/26695642-8b26-494b-a142-54a515db6512 - Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME

我正在使用 chrome v71 和 chromedriver v2.45

有人知道那里发生了什么吗?我该如何解决这个问题?

最佳答案

不幸的是,Chrome 71 在 headless 模式下破坏了 blob URL。如果您针对 Chrome 72 测试版运行,它应该被修复。您可以在 puppeteer 问题中看到讨论 - https://github.com/GoogleChrome/puppeteer/issues/3463

另请注意,您不需要使用 capybara-screenshot gem 来截取该屏幕截图 - 只需调用 page.save_and_open_screenshot

关于selenium-webdriver - 无法加载资源:net::ERR_UNKNOWN_URL_SCHEME 使用 capybara 和 headless chrome 渲染 jstree 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53945865/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com