Forum Discussion

Mohamed14's avatar
Mohamed14
New Contributor
8 years ago

Enabled rows. Desktop applications

I have this window object (see the picture below). I want to count how many rows are enabled. How should I do it? My code looks like this so far. Someone who can help?

 

 

if(Aliases.javaw.AdminEkspertOmraadeWin.ValgbareEkspOmraade.Exists and Aliases.javaw.AdminEkspertOmraadeWin.AfdelingsExpOmraade.Exists) then


set HaandItem = Aliases.javaw.AdminEkspertOmraadeWin

log.Message("ItemCount is :" & HaandItem.ValgbareEkspOmraade.wItemCount )

log.Message("ItemEnabled is :" & HaandItem.ValgbareEkspOmraade. )   ///How do I count enabled rows?

 

 

 

 

 

 

 

 


  • Mohamed14 wrote:

    The problem is that I can always select/click an item even if it is disable. In instead of checking whether an item is enable or disable, I will check how many rows are enabled or disable. 


    Sounds like a bug in your AUT to me... if I can click on an  item and select it, even if it is disabled, that's a problem for the developers to correct.

    Additionally, the whole "enabled/disabled" thing seems to be something custom... as I understand it, the Java Swing List control is just that, a list... the items are just strings in the list... they really don't have an "enabled/disabled" property on them.... so, if there is a concept of "enabled/disabled", this is a custom implementation on top of the default Swing List and your best bet would be to talk with your developers to see what properties they are utilizing to enable/disable an item.

  • Colin_McCrae's avatar
    Colin_McCrae
    8 years ago

    "Sounds like a bug in your AUT to me... if I can click on an  item and select it, even if it is disabled, that's a problem for the developers to correct."

     

    Depends how he's doing it no?

     

    If using a Click() method, then yup, I agree. That's a bug.

     

    If using a native method of the control - Select() or whatever, I don't work with Java controls - then I can easily see that bypassing any validation that prevents the user manually clicking things which are supposed to be disabled. But then, I wouldn't use such direct methods personally. As far as interacting with controls goes, I only use Click/RClick/Keys etc 95% of the time. As ever, because these are closest to normal user behaviour.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Without knowing your actual component and stuff, keep in mind this is a "guess".

     

    Basically, if you have a wItemCount, somewhere on that same object should be a property of "Items" or "Item" or something.  What you need to do, then, is run a for loop through those items and, for each one, check some sort of property to see if it is enabled.  The below code is a best guess and should not be taken as something to copy and paste as is... modifications WILL be necessary.  Additional note... I'm adding "WaitAliasChild" calls to your "Exists" checks to make sure that the objects exist before proceeding...

     

    if(Aliases.javaw.AdminEkspertOmraadeWin.WaitAliasChild('ValgbareEkspOmraade', 10000).Exists and Aliases.javaw.AdminEkspertOmraadeWin.WaitAlosChild('AfdelingsExpOmraade', 10000).Exists) then {
        HaandItem = Aliases.javaw.AdminEkspertOmraadeWin
        log.Message("ItemCount is :" & HaandItem.ValgbareEkspOmraade.wItemCount )
        var enabledCount = 0;
        for (var i=0;  i< HaandItem.ValgbareEkspOmraade.wItemCount; i++) {
            if (HaandItem.ValgbareEkspOmraade.Item(i).Enabled) {
                enabledCount++;
            }
        }
    
    log.Message("ItemEnabled is :" & enabledCount );  

     

     

    • Colin_McCrae's avatar
      Colin_McCrae
      Community Hero

      I'm a little confused?

       

      log.Message("ItemEnabled is :" & HaandItem.ValgbareEkspOmraade. )   ///How do I count enabled rows?

       

      Your log message is for "Item Enabled". Which implies a single item?

       

      But you say you want to count the enabled rows?

       

      Can you clarify which it is?

       

      And, as tristaanogre says, we'll need more info to be accurate. What is the class of the object you're inspecting here? Which properties you need to inspect, and how you get to them (may require some drill-down) depends entirely on the type of object you're dealing with ....

  • Mohamed14's avatar
    Mohamed14
    New Contributor

    This is the property of the object(see attached pic.) and it is possible to check if it is enabled. But I can't check if the items in my object exists or enabled.

     

    I can't use the below code because it is not possible to check if the items exists. 

     

     if (HaandItem.ValgbareEkspOmraade.Item(i).Enabled) {
                enabledCount++;

     

     

    • Colin_McCrae's avatar
      Colin_McCrae
      Community Hero

      There is a "Selected Items" property there?

       

      If you select some items, does it populate? (It's empty in your image ...)

       

      If so, just use that. If it populates as a delimited list, just split it and use the count on the resulting array ....

      • Mohamed14's avatar
        Mohamed14
        New Contributor

        The problem is that I can always select/click an item even if it is disable. In instead of checking whether an item is enable or disable, I will check how many rows are enabled or disable. 

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Mohamed14 wrote:

      This is the property of the object(see attached pic.) and it is possible to check if it is enabled. But I can't check if the items in my object exists or enabled.

       

      I can't use the below code because it is not possible to check if the items exists. 

       

       if (HaandItem.ValgbareEkspOmraade.Item(i).Enabled) {
                  enabledCount++;

       

       


      As mentioned, the code that I posted is not to be interpreted to be used "as-is"... the concept is sound... you have a wItemCount property so, somewhere, there is an wItem or wItems property or something that, somehow, can be used to find and return any of the individual items... each of those items has a set of properties that, somehow, you can inspect to determine if it is enabled... could be an actual Enabled property or something else.

      To sum up...

      1) Use a for loop to loop through the items of your object based upon wItemCount

      2) In the loop, using the loop index, get acccess to each item and check a property to see if it is enabled

      3) In the loop, if the enabled property checks out, increment a counter for the enabled items

      4) Once you exit the loop, use that incremented counter to report the number of enabled items.

      You will DEFINITELY need to adapt the code for your particular components but, essentially, that's how you'll do it.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        OK, now that we see your component, Yeah, the Java Swing List component usually has a wItem property on it that will return the caption of the item... it also should have a wSelectedItems property... 

         

        Now, what you've given us is a screenshot of the MAPPED item... however, what would be better is a screenshot of the item as it shows up in your object browser.  

         

        IF the list is implemented as I think it might be, your code should read something like...

         

        if(Aliases.javaw.AdminEkspertOmraadeWin.WaitAliasChild('ValgbareEkspOmraade', 10000).Exists and Aliases.javaw.AdminEkspertOmraadeWin.WaitAlosChild('AfdelingsExpOmraade', 10000).Exists) then {
            HaandItem = Aliases.javaw.AdminEkspertOmraadeWin
            log.Message("ItemCount is :" & HaandItem.ValgbareEkspOmraade.wItemCount )
            var enabledCount = 0;
            for (var i=0;  i< HaandItem.ValgbareEkspOmraade.wItemCount; i++) {
                if (HaandItem.ValgbareEkspOmraade.wSelected(i)) {
                    enabledCount++;
                }
            }
        
        log.Message("ItemEnabled is :" & enabledCount );  

         

        Again... this MAY or may not work depending upon how your component is implemented but, based upon the information available, this is how I would go.

        Suffice it to say, you are in the best position to determine what properties to check... the methodology as presented should work, you just need to figure out HOW to determine whether or not an item is "enabled" and utilize that within the for loop.