dimanche 1 janvier 2017

Selenium C# How to pause/play an embedded youtube video

So I have this test case in which I open a youtube link which opens a frame with youtube video (embedded) enter image description here

I want to play/pause the video with Selenium. I got an error about no such element. Everything works in other places where I don't have youtube video. This is the code:

    public void PlayMovies()
    {
        driver.FindElement(By.CssSelector("span.movie"), TimeoutToFindElement).Click();
        driver.FindElement(By.CssSelector("li > a.youtubevideo"), TimeoutToFindElement).Click();
        driver.SwitchTo().ActiveElement();


        //driver.FindElement(By.ClassName(".ytp-play-button"), TimeoutToFindElement).Click();
        //driver.FindElement(By.XPath("//div[2]/div/button"), TimeoutToFindElement).Click();
        //driver.FindElement(By.XPath("//*[starts-with(@id,'player_uid')]/div[22]/div[2]/div[1]/button"), TimeoutToFindElement);
        //driver.FindElement(By.CssSelector("button.ytp-play-button.ytp-button"), TimeoutToFindElement).Click();


        driver.FindElement(By.XPath("//div[@id='youtube-modal-container']/div/div/button"), TimeoutToFindElement).Click();
    }

None of those commented line are working. Also I don't know if SwitchTo has some effects, because I get the same error with it or without.

Aucun commentaire:

Enregistrer un commentaire