gpt4 book ai didi

javascript - Testcafe - 处理视频

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:53:27 25 4
gpt4 key购买 nike

我正在测试一个带有嵌入式视频的页面,我可以使用控制台播放、停止和获取当前播放时间。

当我尝试将其转换为 Testcafe 时,出现错误。这是我在控制台上的工作:

var vid = document.querySelector('.video-tech')
if (vid.paused === false) {
vid.pause();
} else {
vid.play();
}
document.querySelector('.video-current-time-display').innerText // 0:33

然后我尝试使用 Testcafe 语法获取这些元素:

const playVideo = ClientFunction(() => {
document.querySelector('.video-tech').play();
});

const pauseVideo = ClientFunction(() => {
document.querySelector('.video-tech').pause();
});

到目前为止一切顺利。问题是我无法使用 If-Else 语句和 ClientFunction

我的目标是从 current-time-display 获取文本并让视频播放几秒钟,然后停止。

最佳答案

这看起来像是浏览器策略限制,您可能需要指定(对于 Chrome 浏览器)--autoplay-policy=no-user-gesture-required 标志 (chrome://标志/#autoplay-policy):

testcafe "chrome --autoplay-policy=no-user-gesture-required" test.js

另请参阅:Start a Browser With Arguments

关于javascript - Testcafe - 处理视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55182940/

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