  | 36 | 36 | | # This is Watir, a web application testing tool for Ruby |
| | 37 | 37 | | # Home page is http://wtr.rubyforge.com |
| | 38 | 38 | | # |
  | 39 | | - | # Version "$Revision: 363 $" |
| | | 39 | + | # Version "$Revision: 366 $" |
| 40 | 40 | | # |
| | 41 | 41 | | # Typical usage: |
| | 42 | 42 | | # # include the controller |
| |
|
|
 |
… |
| 680 | 680 | | table = t |
| | 681 | 681 | | end |
| | 682 | 682 | | end |
  | | 683 | + | tableIndex = tableIndex + 1 |
| 683 | 684 | | end |
| | 684 | 685 | | #puts "table - #{what}, #{how} Not found " if table == nil |
| | 685 | 686 | | clearFrame() |
| |
|
|
 |
… |
| 1647 | 1648 | | # This method selects an item, or items in a select box. |
| | 1648 | 1649 | | # Raises NoValueFoundException if the specified value is not found. |
| | 1649 | 1650 | | # * item - the thing to select, string, reg exp or an array of string and reg exps |
  | 1650 | | - | |
| 1651 | 1651 | | def select( item ) |
  | | 1652 | + | select_item_in_select_list( :text , item ) |
| | | 1653 | + | end |
| | | 1654 | + | |
| | | 1655 | + | |
| | | 1656 | + | # This method selects an item, or items in a select box. |
| | | 1657 | + | # Raises NoValueFoundException if the specified value is not found. |
| | | 1658 | + | # * item - the value of the thing to select, string, reg exp or an array of string and reg exps |
| | | 1659 | + | def select_value( item ) |
| | | 1660 | + | select_item_in_select_list( :value , item ) |
| | | 1661 | + | end |
| | | 1662 | + | |
| | | 1663 | + | |
| | | 1664 | + | |
| | | 1665 | + | # this method is used internally to select something from the select box |
| | | 1666 | + | # * name - symbol :vale or :text - how we find an item in the select box |
| | | 1667 | + | # * item - string or reg exp - what we are looking for |
| | | 1668 | + | def select_item_in_select_list( name_or_value, item ) |
| | | 1669 | + | |
| 1652 | 1670 | | @ieController.clearFrame() |
| | 1653 | 1671 | | raise UnknownObjectException , "Unable to locate a selectbox using #{@how} and #{@what} " if @o==nil |
| | 1654 | 1672 | | if item.kind_of?( Array ) == false |
| |
|
|
 |
… |
| 1657 | 1675 | | items = item |
| | 1658 | 1676 | | end |
| | 1659 | 1677 | | |
  | | 1678 | + | |
| | | 1679 | + | |
| 1660 | 1680 | | highLight( :set) |
| | 1661 | 1681 | | doBreak = false |
| | 1662 | 1682 | | items.each do |thisItem| |
| | 1663 | 1683 | | |
| | 1664 | 1684 | | @ieController.log "Setting box #{@o.name} to #{thisItem} #{thisItem.class} " |
| | 1665 | 1685 | | |
| | 1666 | 1686 | | @o.each do |selectBoxItem| |
  | 1667 | | - | @ieController.log " comparing #{thisItem } to #{selectBoxItem.text}" |
| | 1668 | | - | if thisItem.matches( selectBoxItem.text) |
| | | 1687 | + | @ieController.log " comparing #{thisItem } to #{selectBoxItem.invoke(name_or_value.to_s) }" |
| | | 1688 | + | if thisItem.matches( selectBoxItem.invoke(name_or_value.to_s)) |
| 1669 | 1689 | | matchedAnItem = true |
| | 1670 | 1690 | | if selectBoxItem.selected == true |
  | 1671 | | - | @ieController.log " #{selectBoxItem.text} is already selected" |
| | | 1691 | + | @ieController.log " #{selectBoxItem.invoke(name_or_value.to_s)} is already selected" |
| 1672 | 1692 | | doBreak = true |
| | 1673 | 1693 | | else |
  | 1674 | | - | @ieController.log " #{selectBoxItem.text} is being selected" |
| | | 1694 | + | @ieController.log " #{selectBoxItem.invoke(name_or_value.to_s)} is being selected" |
| 1675 | 1695 | | selectBoxItem.selected = true |
| | 1676 | 1696 | | @o.fireEvent("onChange") |
| | 1677 | 1697 | | doBreak = true |
| |
|
|
 |
… |
| 1681 | 1701 | | end |
| | 1682 | 1702 | | end |
| | 1683 | 1703 | | |
  | 1684 | | - | raise NoValueFoundException , "Selectbox was found, but didnt find item #(item) " if doBreak == false |
| | | 1704 | + | raise NoValueFoundException , "Selectbox was found, but didnt find item with #{name_or_value.to_s} of #{item} " if doBreak == false |
| 1685 | 1705 | | end |
| | 1686 | 1706 | | highLight( :clear ) |
| | 1687 | 1707 | | end |
  | | 1708 | + | |
| | | 1709 | + | private :select_item_in_select_list |
| | | 1710 | + | |
| | | 1711 | + | |
| | | 1712 | + | |
| | | 1713 | + | |
| | | 1714 | + | |
| | | 1715 | + | |
| | | 1716 | + | |
  | 1688 | 1717 | | |
| | 1689 | 1718 | | # This method returns all the items in the select list as an array. An empty array is returned if the select box has no contents. |
| | 1690 | 1719 | | # Raises UnknownObjectException if the select box is not found |