If you have a page that looks like this:
<a href="http://google.com">google.com</a> <a href="http://facebook.com">facebook.com</a>
You can get href attribute of all links with:
browser.links.each do |link|
puts link.href
end
When you execute the code, output should be:
http://google.com/ http://facebook.com/
links is not the only collection of HTML elements that Watir supports. For the rest of the collections, take a look at the table on this page.
| Watir Method | HTML element |
|---|---|
| areas | <area> |
| buttons | <button> <input type="button"> <input type="image"> <input type="reset"> <input type="submit"> |
| checkboxes | <input type="checkbox"> |
| dds | <dd> |
| divs | <div> |
| dls | <dl> |
| dts | <dt> |
| ems | <em> |
| file_fields | <input type="file"> |
| forms | <form> |
| ? | <frame> <iframe> |
| ? | <h1><h2><h3><h4><h5><h6> |
| hiddens | <input type="hidden"> |
| images | <img> |
| labels | <label> |
| lis | <li> |
| links | <a> |
| maps | <map> |
| ps | <p> |
| pres | <pre> |
| radios | <input type="radio"> |
| select_lists | <select> |
| spans | <span> |
| strongs | <strong> |
| tables | <table> |
| bodies | <tbody> |
| cells | <td> |
| rows | <tr> |
| text_fields | <input> <input type="password"> <input type="text"> <textarea> |
| uls | <ul> |
Comments (1)
Oct 02
Zeljko says:
I have noticed that table cells and rows are have TableCells and TableRows class...I have noticed that table cells and rows are have TableCells and TableRows class names, but table bodies has Bodies class name (I was expecting TableBodies).
I could not find collections for frames and h1-h6. Please let me know if I missed it, or confirm if you know it is not implemented, so I can mark it appropriately.