2014-09-22 12 views
8

Chcesz uzyskać zawartość meta opisu strony za pomocą webdrivera.Pobierz treść opisu meta ze strony internetowej używając selenu webdriver

powiedzmy, od dołu DOM chcą odzyskać tekst 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"> 

Próbowałem z

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

Ale powyższy kod nie pracował dla mnie.

Odpowiedz

10

Próbujesz uzyskać wartość atrybutu, więc zamiast getText() użytku getAttribute():

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