【问题标题】:c# Selenium How to click on the play button of a youtube video embedc# Selenium 如何点击嵌入 youtube 视频的播放按钮
【发布时间】:2020-05-02 17:53:18
【问题描述】:

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

我的代码:

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

博主youtube视频播放点击代码是什么?

谢谢!

【问题讨论】:

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

    【讨论】:

      猜你喜欢
      • 2017-02-22
      • 1970-01-01
      • 2015-06-20
      • 1970-01-01
      • 2014-12-01
      • 2012-07-09
      • 2020-08-25
      • 1970-01-01
      • 2023-03-07
      相关资源
      最近更新 更多