【发布时间】:2014-04-24 03:32:38
【问题描述】:
我正在尝试使用以下代码阅读 youtube 视频 cmets:
FirefoxDriver driver = new FirefoxDriver();
driver.get("https://www.youtube.com/watch?v=JcbBNpYkuW4");
WebElement element = driver.findElementByCssSelector("#watch-discussion");
System.out.println(element.getText()); // this prints: loading..
// scrolll down so that comments start to load
driver.executeScript("window.scrollBy(0,500)", "");
Thread.sleep(10000);
element = driver.findElementByCssSelector("#watch-discussion");
System.out.println(element.getText());
最后一条语句打印一个空字符串。为什么?
【问题讨论】:
-
在
<div> watch-discussion里面有一个iframe,你需要switchTo()那个框架,webdriver才能看到它的内容。
标签: java javascript selenium youtube