youtube - 在Java中使用Selenium Webdriver自动执行youtube视频时出错

标签 youtube automation

在Java中使用Selenium Webdriver尝试在youtube中自动执行视频操作时出现以下错误。

我已经从下面的链接复制了代码以实现自动化。

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



以下是我遇到的错误

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...)



我是否缺少安装/配置YouTube视频的自动化功能?
自从两天以来,这使我发疯。

最佳答案

我解决了这个问题,代码看起来像

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

        }

    }

关于youtube - 在Java中使用Selenium Webdriver自动执行youtube视频时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32204767/

相关文章:

java - 在 Java 中解析 Youtube API 日期

excel - 在哪里可以找到 Excel 支持的所有 OLE 调用的引用指南

perl - 在 Perl 中自动处理 Excel 文件并避免对话框/UI 交互

rest - SoapUI 使用 groovy 打印剩余请求的完整 URL 路径

youtube - 如何检查允许在哪个国家/地区播放 YouTube 视频?

javascript - 如何在JavaScript中获取过去的X-Frame-Options

iphone - 将 youtube.com 中的视频嵌入到 iPhone 应用程序中

facebook - Facebook的统一SDK/用户/提要嵌入YouTube的链接

git - 最佳实践 - Git + 构建自动化 - 保持配置独立

Selenium 和数据库测试