ByNovice
ByNovice

Reputation: 25

c# Selenium How to click on the play button of a youtube video embed

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

Mycode:

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

blogger youtube video play click What is the code ?

Thank you!

Upvotes: 1

Views: 1142

Answers (1)

dpapadopoulos
dpapadopoulos

Reputation: 1846

I inspected the platform that you posted. In order to click on the play button, you have to enter into the iframe:

enter image description here

In order to do that check the following example:

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();

If you need further detail for this you can visit the official website of Selenium (it's the browser manipulation section).

Upvotes: 2

Related Questions