c# - c# Selenium 如何点击嵌入 youtube 视频的播放按钮
问题描述
https://pinstopins.blogspot.com/2020/04/sayac-canl.html
我的代码:
driver1.FindElement(By.XPath("//button[@class='ytp-large-play-button ytp-button'")).Click();
博主youtube视频播放点击代码是什么?
谢谢!
解决方案
我检查了您发布的平台。为了点击播放按钮,您必须进入 iframe:
为此,请检查以下示例:
self.driver1 = webdriver.Firefox()
# Locate the iframe using the tag attribute.
driver1.SwitchTo.Frame(driver.FindElement(By.TagName("iframe"))
# After locating and entering into the iframe you now have access to the given video and you can click on that.
driver1.FindElement(By.XPath("//button[@class='ytp-large-play-button ytp-button'")).Click();
# After clicking on the button, I guess you don't need it anymore so you have to out of the iframe into the default content. So, you execute the following line.
driver.switchTo().defaultContent();
如果您需要更多详细信息,可以访问Selenium的官方网站(这是浏览器操作部分)。
推荐阅读
- java - 如何使用`@Backoff`注释中的属性文件中的属性来自定义延迟时间?
- c# - 如何转换此代码以便在 Unity 中使用?
- excel - 将复杂的日期函数转换为
- html-table - markdown-it:在 .md 文件中格式化表格
- reactjs - Webpack 在文件更改时提供另一个 url
- python - Python - 打开一个文件
- windows - 在笔记本电脑上恢复出厂设置
- python - 使用 SpaCy 和 Pandas 更快地提取 NER
- node.js - 使用 Nodejs 时出现权限错误
- google-cloud-platform - 谷歌语音识别弱日期转录