使用Java中的Selenium Chrome驱动程序测试视频对象

时间:2016-03-11 17:13:54

标签: java google-chrome selenium video selenium-webdriver

我正在开发硒测试以使用 Chrome浏览器上的 ChromeDriver 检测视频是否存在。

当以下代码点击chromedriver.get("http://d3o006n2t0jcdj.cloudfront.net/8348d175-9468-4b6c-9781-6dba4fdf4bfd.mp4")时,它会在浏览器中打开它,并播放视频,但永远不会点击下一行来捕获与其关联的WebElement

如何确保在Chrome浏览器中打开视频的那一刻,它会点击下一行来捕获“WebElement”?请让我知道我做错了什么。

try {
    chromeDriver = new ChromeDriver();
    chromeDriver.get("http://d3o006n2t0jcdj.cloudfront.net/8348d175-9468-4b6c-9781-6dba4fdf4bfd.mp4");
    WebElement videoCloudObject = chromeDriver.findElement(By.xpath("/html/body/video/source"));
    logger.info("Video Cloud Object " + videoCloudObject + " .. Moving object  " + nonDuplicateVideoList.get(i));
} catch (Exception ex) {
    logger.error("Moving object does not exist  " + nonDuplicateVideoList.get(i));
    Assert.fail("Video cannot be played as Moving image object does not exist " + nonDuplicateVideoList.get(i));
} finally {
    chromeDriver.close();
}

1 个答案:

答案 0 :(得分:0)

问题出在"裸" catch子句。我怀疑selenium会找到该元素,但是当您尝试在此处连接字符串和WebElement实例时会发生错误:

logger.info("Video Cloud Object " + videoCloudObject + " .. Moving object  " + nonDuplicateVideoList.get(i));

相反,您可能希望获得src元素的source属性:

videoCloudObject.getAttribute("src")