http://slashdot.org/ 打印页面上有多少文章,因为它每天都会动态更改。 打印文章中使用的唯一图标列表。
答案 0 :(得分:0)
你好找到下面的答案
public class latestNews {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://slashdot.org/");
// take everything inside the list for article
List<WebElement> latestNews = driver.findElements(By.className("story"));
// take everything for icon inside the list
List<WebElement> releventicons = driver.findElements(By.xpath("//*[@class='topic']/a/img"));
// print total number of latest articles for today
System.out.println("Total article for today is : " + latestNews.size());
// also plz note that size of icons will also be same as articles
// print headings and icons of the total number of articles for today
for(int i =0;i<latestNews.size();i++){
System.out.println("Article for today is : "+ latestNews.get(i).getText() + "=="+ releventicons.get(i).getAttribute("alt"));
}
}
}
答案 1 :(得分:0)
只需使用:
List<WebElement> totalarticale = driver.findElements(By
.cssSelector(" #firehoselist>article"));
System.out.println("size is "+totalarticale.size());
文章图标编号与编号相同。