我正在为播放DRM内容的HTML5播放器编写一些硒测试,当我手动测试时,播放器在Chrome中工作正常,但如果我运行我的测试用例,则不会在最新的Chrome驱动程序中加载或播放任何内容。
是否因为drm内容未被授权使用Chrome驱动程序或其他内容?
对于用selenium编写的其他函数运行测试没有问题。 有什么想法吗?
答案 0 :(得分:4)
Chromedriver默认使用--disable-component-update
开关启动Chrome,这会禁用NaCl(Native Client)支持,而这又支持加载DRM模块(例如Widevine Modular DRM)。
要解决此问题,您需要告知驱动程序不要使用此开关启动Chrome,方法是使用excludeSwitches
选项构建驱动程序,并指定disable-component-update
参数。例如(JS):
var webdriver = require('selenium-webdriver');
var chrome = require("selenium-webdriver/chrome");
var capabilities = new webdriver.Capabilities.chrome();
var chromeOptions = {
'args': ['--user-data-dir=C:/ChromeProfile'], // start with pre-configured Chrome profile
'excludeSwitches': ['disable-component-update'] // stop breaking Native Client support
};
capabilities.set('chromeOptions', chromeOptions);
var driver = new webdriver.Builder().
withCapabilities(capabilities).
build();
driver.get('http://...');
或者使用Python绑定:
from selenium import webdriver
def buildDriver():
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['disable-component-update'])
options.add_argument('--user-data-dir=C:/Temp/ChromeProfile')
return webdriver.Chrome(chrome_options=options)
希望有所帮助..
- ab1
Issue 886: Enabled PNaCl Components in ChromeDriver - Enhancement
答案 1 :(得分:1)
如果你无法得到@ Chainik的工作答案,那就试试吧。它对我有用。
根据https://bugs.chromium.org/p/chromedriver/issues/detail?id=1140,你可以通过做一些事情解决这个问题。
使用这些命令行参数
从终端/命令提示符手动启动chrome-- google-chrome --user-data-dir=/path/to/any/custom/directory/home/user/Desktop/Chromedir --profile-directory="Profile 1" --remote-debugging-port=7878
- 确保“配置文件1”已存在于同一个--user-data-dir中(make usre Profile 1具有必要的chrome:// components /在手动启动时运行Netflix)
- 您可以使用任何免费端口代替7878 验证http://localhost:7878是否正在运行并返回值。 现在通过chromedriver连接到remote-debugging-port = 7878,代码如下 验证chrome:// components /
醇>
我将我的文件放入.bat文件,但您可以为bash脚本或其他任何内容执行相同操作:
C:/Program Files (x86)/Google/Chrome/Application/chrome.exe --user-data=c:/temp/chromeprofile --profile-directory="Profile 1" --remote-debugging-port=7878
然后在代码中设置调试器地址以使用浏览器:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
cr_options = Options()
# This line is where the "magic" happens.
cr_options.add_experimental_option('debuggerAddress','127.0.0.1:7878')
browser = webdriver.Chrome(chrome_options=cr_options)
browser.get('https://www.google.com')
browser.get('chrome://components/')
答案 2 :(得分:0)
我发布了一个java版本的Chainik的答案作为使用Java的人的参考,请告诉我是否有任何错误。
ChromeOptions options = new ChromeOptions();
List<String> list = new ArrayList<String>();
list.add("disable-component-update");
options.setExperimentalOption("excludeSwitches", list);
options.addArguments("user-data-dir=/Users/myname/Library/Application Support/Google/Chrome/Default");
java.lang.System.setProperty("webdriver.chrome.driver","/usr/bin/chromedriver");
Webdriver driver = new ChromeDriver(options);
这是关于chromedriver功能和选项的article。
答案 3 :(得分:0)
这已经晚了,但可能会帮助其他人。我能够通过不使用无头浏览器来解决这个问题并播放视频。
在 Python 中,
options = Options()
options.headless = False
webdriver.Chrome(executable_path='path/to/chromedriver', options=options)