2014-09-22 93 views
8

想要使用webdriver获取页面元描述的内容。使用selenium webdriver从网页中检索元描述的内容

让说,从下面DOM要检索的文本 Test.com provides a complete software solution for creating online tests and managing enterprise and specialist certification programs, in up to 22 languages

<script src="content/js/jquery.min.js"> 
<meta content="Test.com provides a complete software solution for creating online tests and managing enterprise and specialist certification programs, in up to 22 languages." name="description"> 
<meta content="Test.com" name="keywords"> 

我试着用

System.out.println(driver.findElement(By.xpath("//meta[@name='description']")).getText()); 

但上面的代码不会为我工作。

回答

10

你试图得到一个属性值,所以不是getText()使用getAttribute()

driver.findElement(By.xpath("//meta[@name='description']")) 
     .getAttribute("content") 
相关问题