2014-09-22 64 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") 
相關問題