gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 05:32:07 25 4
gpt4 key购买 nike

在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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com