1

Getting the below error while trying to automate the video in youtube using selenium webdriver in java.

I have copied the code to automate from the below link.

https://seleniumonlinetrainingexpert.wordpress.com/2012/12/03/how-to-automate-youtube-using-selenium-webdriver/

Below is the error I am getting

Exception in thread "main" org.openqa.selenium.WebDriverException: document.movie_player is undefined Command duration or timeout: 23 milliseconds Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:17:10' System info: host: 'HYDPCM99232L', ip: '10.1.1.3', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_79' Session ID: a573f5f2-29c4-4b62-a5f2-54e44a762547 Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=40.0.2}] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:605) at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:514) at FlexWebDriver.callFlashObject(FlexWebDriver.java:23) at Youtube.main(Youtube.java:17) Caused by: org.openqa.selenium.WebDriverException: document.movie_player is undefined Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:17:10' System info: host: 'HYDPCM99232L', ip: '10.1.1.3', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_79' Driver info: driver.version: unknown at .anonymous(.....youtube link...)

Am I missing anything to install/configure to automate youtube videos? This is driving me crazy since 2 days.

4
  • is this problem solved? Commented Jul 2, 2016 at 13:10
  • yes...i resolved the problem...thanks Commented Jul 22, 2016 at 7:06
  • how did you do it? please answer your question. Commented Jul 23, 2016 at 6:08
  • I had fixed the problem and the code looks like Commented Jul 24, 2016 at 23:11

1 Answer 1

1

I solved the problem and the code looks like

import org.openqa.selenium.By;
    import org.openqa.selenium.JavascriptExecutor;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.testng.annotations.Test;

    public class YouTube {

        @Test
        public void test1() throws InterruptedException {
            //Initialising the firefox driver
            FirefoxDriver driver = new FirefoxDriver();

            driver.manage().window().maximize();
            //navigating to the below url 
            driver.get("https://www.youtube.com/watch?v=qxoXvn2l2gA");

            Thread.sleep(5000L);

            WebElement video = driver.findElement(By.tagName("video"));
            JavascriptExecutor js = driver;

             //pausing the video
            js.executeScript("arguments[0].pause();", video);

            Thread.sleep(5000L);

//playing the video         
js.executeScript("arguments[0].play();", video);
            Thread.sleep(5000L);

//muting the video          
js.executeScript("arguments[0].mute();", video);
            Thread.sleep(5000L);

//unmuting the video            
js.executeScript("arguments[0].unMute();", video);
            Thread.sleep(5000L);

//Dragging the video            
js.executeScript("arguments[0].currentTime = 600;", video);
            Thread.sleep(5000L);

            js.executeScript("alert(arguments[0].readyState);", video);

            driver.quit();

        }

    }
Sign up to request clarification or add additional context in comments.

1 Comment

Hmm... could you edit your answer to add comments that throroughly explain what does the code do? Doing so would make the answer more useful to future visitors (and more likely to get upvotes).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.