提问人:김수연 提问时间:10/20/2023 最后编辑:JohnM김수연 更新时间:10/20/2023 访问量:22
等到 addEventListener Selenium、Excel VBA
Wait Until addEventListener Selenium, Excel VBA
问:
我正在用VBA制作一本词汇书。我什至从一个名为 Wordreference 的网站中提取了一个指向语音文件的链接,但我编写此代码是为了在 Excel 中播放该链接。我最初尝试将 .wav 文件下载到我的 PC,但由于公司的安全程序,这是不可能的,所以我想直接运行互联网并播放它。但是,即使链接成功,也存在一个问题,即 Internet 窗口在完全播放之前关闭。
Sub edGe()
Dim edGe As New EdgeDriver
With edGe
.Start
.Get "http://sousound.com/music/healing/healing_01.mp3"
Set videoElement = .FindElementByTag("video")
If Not videoElement Is Nothing Then
jsScript = "const video = document.querySelector('video');" & _
"video.addEventListener('ended', function(){" & _
"console.log('video stopped');" & _ ' // it works on Edge development Console
window.close();" & _
~"});" ' // It doesn't Work Error → Scripts may close only the windows that were opened by them.
.ExecuteScript jsScript, videoElement
End If
End With
' So i wrote new code
' But i dont know how to do get EventListener On VBA Code ...
t = Timer
Do
DoEvents
On Error Resume Next
Set ele = .FindElementByName("ended"
On Error GoTo 0
If Timer - t = 10 Then Exit Do <== To infinite loop
Loop While ele Is Nothing
End Sub
我之前的问题如何在Excel VBA上使用Selenium Edgedriver检测HTML音频
我指的是 Selenium Webdriver (VBA):显式等待
也 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video
https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/ended_event
答: 暂无答案
评论