Reputation: 875
Want to get the content of meta description of page using webdriver.
Let say , from below DOM want to retrieve text
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">
I tried with
System.out.println(driver.findElement(By.xpath("//meta[@name='description']")).getText());
But above code not worked for me.
Upvotes: 13
Views: 13016
Reputation: 875
you could also try for
driver.findElement(By.xpath("//*[@name='description']"))
.getAttribute("content")
Upvotes: 0
Reputation: 89285
You're trying to get an attribute value, so instead of getText()
use getAttribute()
:
driver.findElement(By.xpath("//meta[@name='description']"))
.getAttribute("content")
Upvotes: 17