我正在开发硒测试以使用 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();
}
答案 0 :(得分:0)
问题出在"裸" catch子句。我怀疑selenium会找到该元素,但是当您尝试在此处连接字符串和WebElement
实例时会发生错误:
logger.info("Video Cloud Object " + videoCloudObject + " .. Moving object " + nonDuplicateVideoList.get(i));
相反,您可能希望获得src
元素的source
属性:
videoCloudObject.getAttribute("src")