【问题标题】:Error while automating youtube video using selenium webdriver in java在 java 中使用 selenium webdriver 自动化 youtube 视频时出错
【发布时间】:2016-07-27 14:14:57
【问题描述】:

尝试在 youtube 中使用 java 中的 selenium webdriver 自动执行视频时出现以下错误。

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

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

以下是我遇到的错误

线程“主”org.openqa.selenium.WebDriverException 中的异常:document.movi​​e_player 未定义 命令持续时间或超时:23 毫秒 构建信息:版本:'2.46.0',修订:'87c69e2',时间:'2015-06-04 16:17:10' 系统信息:主机:'HYDPCM99232L',ip:'10.1.1.3',os.name:'Windows 7',os.arch:'x86',os.version:'6.1',java.version:'1.7.0_79 ' 会话 ID:a573f5f2-29c4-4b62-a5f2-54e44a762547 驱动信息:org.openqa.selenium.firefox.FirefoxDriver 功能 [{platform=WINDOWS,acceptSslCerts=true,javascriptEnabled=true,cssSelectorsEnabled=true,databaseEnabled=true,browserName=firefox,handlesAlerts=true,nativeEvents=false,webStorageEnabled=true,rotatable=false,locationContextEnabled=true,applicationCacheEnabled=true ,需要屏幕截图=true,版本=40.0.2}] 在 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 在 sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 在 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 在 java.lang.reflect.Constructor.newInstance(Constructor.java:526) 在 org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204) 在 org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156) 在 org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:605) 在 org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:514) 在 FlexWebDriver.callFlashObject(FlexWebDriver.java:23) 在 Youtube.main(Youtube.java:17) 原因:org.openqa.selenium.WebDriverException:document.movi​​e_player 未定义 构建信息:版本:'2.46.0',修订:'87c69e2',时间:'2015-06-04 16:17:10' 系统信息:主机:'HYDPCM99232L',ip:'10.1.1.3',os.name:'Windows 7',os.arch:'x86',os.version:'6.1',java.version:'1.7.0_79 ' 驱动程序信息:驱动程序版本:未知 在 .anonymous(.....youtube 链接...)

我是否缺少任何要安装/配置来自动化 youtube 视频的东西? 这两天让我发疯了。

【问题讨论】:

  • 这个问题解决了吗?
  • 是的...我解决了这个问题...谢谢
  • 你是怎么做到的?请回答您的问题。
  • 我已经解决了问题,代码看起来像

标签: youtube automation


【解决方案1】:

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

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

        }

    }

【讨论】:

  • 嗯...您能否edit your answer 添加 cmets 以彻底解释代码的作用?这样做会使答案对未来的访问者更有用(并且更有可能获得支持)。
猜你喜欢
  • 2016-08-29
  • 2016-04-09
  • 2013-07-11
  • 1970-01-01
  • 1970-01-01
  • 2023-03-03
  • 1970-01-01
  • 1970-01-01
  • 2012-11-23
相关资源
最近更新 更多