Reputation: 563
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.
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.
Upvotes: 1
Views: 2054
Reputation: 563
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();
}
}
Upvotes: 1