Issues faced while Automating Youtube with Selenium webdrive | Selenium Forum
M
Posted on 30/06/2016
Hi,
While automating Youtube video in firefox with selenium webdriver I am betting below error:

"===================================================
Exception in thread "main" org.openqa.selenium.WebDriverException: document.movie_player is undefined
Command duration or timeout: 74 milliseconds
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'soumya-PC', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_92'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=44.0, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 5f068408-89fd-4b4c-81b2-b611c0c72ef8
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:577)
at InteractionWithFlash.FlashObjectWebDriver.call(FlashObjectWebDriver.java:28)
at InteractionWithFlash.Youtube.main(Youtube.java:19)
Caused by: org.openqa.selenium.WebDriverException: document.movie_player is undefined
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'soumya-PC', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_92'
Driver info: driver.version: unknown
at <anonymous class>.anonymous(https://www.youtube.com/watch?v=Wy1wDddTcr0&list=UUQc_OGfP0IsgOWT0vosmQjg&index=0&feature=plcp line 69 > Function:1)
at <anonymous class>.handleEvaluateEvent(https://www.youtube.com/watch?v=Wy1wDddTcr0&list=UUQc_OGfP0IsgOWT0vosmQjg&index=0&feature=plcp:69)
'==================================================================
I have created below two.java classes ---

'================================
package InteractionWithFlash;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;


public class FlashObjectWebDriver {
private final WebDriver webDriver;
private final String flashObjectId;

public FlashObjectWebDriver(final WebDriver webDriver, final String flashObjectId) {
this.webDriver = webDriver;
this.flashObjectId = flashObjectId;
}

/*public String click(final String objectId, final String optionalButtonLabel) {
return callFlashObject("doFlexClick", objectId, optionalButtonLabel);
}

public String click(final String objectId) {
return click(objectId, "");
}*/



public String call(final String functionName, final String... args) {
final Object result =
((JavascriptExecutor)webDriver).executeScript(
makeJsFunction(functionName, args),
new Object[0]);

return result != null ? result.toString() : null;
}

private String makeJsFunction(final String functionName, final String... args) {
final StringBuffer functionArgs = new StringBuffer();

if (args.length > 0) {
for (int i = 0; i < args.length; i++) {
if (i > 0) {
functionArgs.append(",");
}
functionArgs.append(String.format("'%1$s'", args[i]));
}
}
return String.format(
"return document.%1$s.%2$s(%3$s);",
flashObjectId,
functionName,
functionArgs);
}

}
'========================================
And another one---
'=================================
package InteractionWithFlash;
import org.openqa.selenium.firefox.FirefoxDriver;


public class Youtube {
static String flashObjid="movie_player";
public static void main(String[] args) throws InterruptedException {
FirefoxDriver driver = new FirefoxDriver();


driver.manage().window().maximize();
Thread.sleep(5000L);
FlashObjectWebDriver flashApp=null;

driver.get("http://tinyurl.com/bqnaoo7");
Thread.sleep(20000L);
flashApp = new FlashObjectWebDriver(driver, flashObjid);
// let the video load
while (Integer.parseInt(flashApp.call("getPlayerState")) == 3){
Thread.sleep(1000L);
}

// Play the video for 10 seconds
Thread.sleep(5000);
flashApp.call("pauseVideo");
Thread.sleep(5000);
flashApp.call("playVideo");
Thread.sleep(5000);
flashApp.call("seekTo","140","true");
Thread.sleep(5000);
flashApp.call("mute");
Thread.sleep(5000);
flashApp.call("setVolume","50");
Thread.sleep(5000);


}

}
'===============================
I am running only Youtube.java class.Can you let me know where the issue is coming???As I followed all steps.

M
Replied on 30/06/2016

are you having this problem?

http://stackoverflow.com/questions/32204767/error-while-automating-youtube-video-using-selenium-webdriver-in-java


M
Replied on 02/07/2016

yes...exactly......what is th solution

even the flex code provided in tutorial is giving the same error


M
Replied on 04/07/2016

have you tried Firefox profile?


M
Replied on 09/07/2016

As per the code ..I have tried in Normal firefox.Can you please let me know what to try in firefox profile?


M
Replied on 11/07/2016

http://toolsqa.com/selenium-webdriver/custom-firefox-profile/