c# - C#Selenium如何单击嵌入的youtube视频的播放按钮

标签 c# selenium selenium-webdriver youtube blogger

https://pinstopins.blogspot.com/2020/04/sayac-canl.html

我的代码:

driver1.FindElement(By.XPath("//button[@class='ytp-large-play-button ytp-button'")).Click();

博客作者youtube视频播放单击什么代码?

谢谢!

最佳答案

我检查了您发布的平台。为了点击播放按钮,您必须输入iframe:

enter image description here

为此,请检查以下示例:

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的官方网站(这是浏览器操作部分)。

关于c# - C#Selenium如何单击嵌入的youtube视频的播放按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61563895/

相关文章:

c# - 在哪里可以安全地存储 ClickOnce 部署的数据文件?

c# - 为什么 Outlook 在使用 Office 互操作时崩溃?

selenium - 如何选择 selenium 中 id 中有句点的元素?

java - 我是 Selenium 新手,但为什么 Maven 会跳过我的测试并告诉我构建成功?

c# - 是否可以在数据对象中使用代码契约的不变量?

c# - RC 更新后的 ASP.NET WebAPI XML 序列化

java - 如何在断言中将值写入字符串

selenium-webdriver - Python Selenium 获取数据失败

javascript - 如何使用 Selenium 和 Python 更改 DOM 中的属性值

javascript - 如何在 Protractor 中单击同一个按钮超过 50 次?