我无法通过cssselector
甚至xpath
进行点击,甚至无法发送密钥空间或输入。
我认为youtube正在阻止它。任何帮助表示赞赏。
我的代码:
Public Function OpenVideo(video As String)
Try
Form1.UpdateStatus("Opening video ...")
If (Driver Is Nothing) Then
Return ""
End If
_Status = True
Driver.Navigate().GoToUrl(video)
'Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5)
'TESTING
' Driver.SwitchTo.Frame(0)
Dim element = Driver.FindElementByCssSelector("#movie_player > div.ytp-chrome-bottom > div.ytp-chrome-controls > div.ytp-left-controls > span:nth-child(2) > button[aria-label='Play (k)'")
element.click()
ViewsByVideo = 0
d = DateTime.Now
If (clockTimer Is Nothing) Then
Dim autoEvent As New AutoResetEvent(False)
clockTimer = New Timer(AddressOf ClockFunction, autoEvent, 0, 1000)
Else
clockTimer.Change(0, 1000)
End If
IsPlaying = True
Catch ex As Exception
LogManager.AddLog(ex.Message)
End Try
_Status = False
End Function
如果可能,我不想单击元素或按钮,而只是单击“命中空格”,这样我就可以确保它总是按play键,因为空格和play一样。
谢谢
答案 0 :(得分:0)
google blocks automated traffic
在最后一步尝试使用cssSelector
。
如果这不起作用,则可能是页面出现DOM问题或自动脚本被阻止了。