Menu

Finding buttons only by text or icon ?

Help
2004-06-21
2013-04-09
  • Stefan Rautenberg

    Hi all,
    we are evaluating JFCUnit for the first time. It  seems that buttons in an application can be only found by the Finder classes via their name (button.setText()) or their icon (button.setIcon()).

    What if we have several buttons on the screen all having the same text on it ("...") or having the same icon (e.g. a trash can). Is there another way to identify a unique button ?

    Could specifying the index of the component inside the container bring a solution ? What exactly does the index mean to JFCUnit ?

    Thanx a lot for any hints on that.

    Regards,
    Stefan

     
    • B.Modi

      B.Modi - 2004-06-21

      Stefan,

      If all other things are equal, (same text, same parent container, etc.) then there is no other way to distinguish the buttons other than using one of the find methods with an index or a findAll method to return all the components meeting your search criteria.

      I believe the components are indexed in the order that they were added to the parent container (Can anyone confirm this?).

      Sometimes I find using the included browser application helpful in determining other ways to search for component.  Start junit.extensions.jfcunit.tools.ComponentBrowser alongside your application to view component properties.  Sometimes specifying the class type or the container it is placed within can help narrow the search.

      Regards,
      B.Modi

       
    • Kevin L Wilson

      Kevin L Wilson - 2004-06-28

      You may also want to perform a find on a label and then navigate up to the container. Then search within the container for the single button. If this makes sence in your GUI.

      You could also extend the button finder to use the AccessibleText, as this may also be unique.

      There are several ways you could accomplish this, however, most things would be dependent on navigating your specific component Hierarchy.

      Cheers, Kevin

       
    • lpelton

      lpelton - 2004-07-02

      you can also search using the name of the button (JButton.setName()) at least that is how i did it. hope this helps

       
    • Jero Cortés

      Jero Cortés - 2009-02-11

      And what about the "matchPattern" method of the Finder class and subclasses?

      "protected final boolean matchPattern(java.lang.String componentAttribute,
                                           java.lang.String patternString,
                                           org.apache.regexp.RE re)

      This method is used to filter components' attributes based on a pattern specified by the user. For example, to search for all windows with title matching 'testWindow*'. Note: If the patternString is null, we need to avoid the PatternCompiler.compile() throwing a NullPointerException and in this case, return true if the componentAttribute is also null. The pattern syntax can be found at the Jakarta RegExp API Documentation in RE.

          Parameters:
              componentAttribute - The attribute text of the component to match against
              patternString - The pattern to match with
              re - The RE pattern matcher to be used
          Returns:
              boolean whether the pattern is contained within the components' attribute text "

       

Log in to post a comment.