【问题标题】:c# Selenium How to click on the play button of a youtube video embedc# Selenium 如何点击嵌入 youtube 视频的播放按钮
【发布时间】:2020-05-02 17:53:18
【问题描述】:
【问题讨论】:
标签:
c#
selenium
selenium-webdriver
youtube
blogger
【解决方案1】:
我检查了您发布的平台。要点击播放按钮,您必须进入 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的官方网站(这是浏览器操作部分)。