我有一个html页面:
<video crossorigin="anonymous" class="" id="video" playsinline="true"
src="https://df.dfs.bnt.com/
DEEAB832j06E9j413FjAA8Dj2zxc535DA2072E3jW01j15579/mp4-
hi/jFNf2IbBoGF28IzyU_WqkA,1535144598/zxxx/
contents/1/8/1a57ae021173751b468cca136e0192.mp4?
rnd=0.38664488150364296">
</video>
通过Selenium WebDriver,我尝试获取视频网址:
By videoLocator = By.id("video");
WebElement videoElement = driver.findElement(videoLocator);
String videoUrl = videoElement.getAttribute("src");
但是 videoUrl -始终返回“” (为空)。
例如,不过:
videoElement.getAttribute("crossorigin")
返回正确答案:“ 匿名”。
我尝试使用javascript从src属性获取此网址:
String videoUrl = (String) js.executeScript("return document.getElementById( 'video' ).getAttribute( 'src' );");
但结果仍然相同:“” 。
我想问题出在 crossorigin =“ anonymous” ,但该怎么办?如何获得src值?
对不起,我的英语不好。
答案 0 :(得分:0)
尝试获取innerHTML属性。代码:
By videoLocator = By.id("video");
WebElement videoElement = driver.findElement(videoLocator);
String videoUrl = videoElement.getAttribute("innerHTML");
答案 1 :(得分:0)
根据您提供的HTML,您需要引入 WebDriverWait ,并且可以使用以下解决方案:
||In function 'int main()':|
'thread' is not a member of 'std'|
't1' was not declared in this scope|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|