Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
How can I extract text from: <div class="listview-total">Total: 4 Reservation(s)</div>
How can I extract text using Selenium from the following:
<div class="listview-total">Total: 4 Reservation(s)</div>
I want an object that contains the string "Total: 4 Reservation(s)"
Greg Kaleka39,021 Points
id, you can't use
document.getElementById() - you have to instead use
document.getElementByClassName(), which returns a array. If you've only got the one element on your page with that class, then you can simply take the first element in that array, and use the attribute
textContent to get the text between the tags.
var theDiv = document.getElementsByClassName("listview-total"); var text = theDiv.textContent
Let me know if this isn't what you're after!