IList; is it possible to refresh?

Class library usage, coding and language questions.
agroenen
Posts: 17
Joined: Thu Jun 09, 2016 3:18 pm

IList; is it possible to refresh?

Post by agroenen » Tue Jun 12, 2018 12:01 pm

We have a few screens where repository-items are visible multiple times.
This code clicks on all of them:

Code: Select all

            public void ClickAlleElementen(Ranorex.Core.Repository.RepoItemInfo K2WItem)  
            {

            	IList<Unknown> elementList = K2WItem.CreateAdapters<Unknown>();  
                  
            		foreach (Ranorex.Unknown element in elementList)
                		{  
                    		element.Click();
                		}	
            }
But sometimes clicking on the element means deleting; so the element isn't on the screen anymore, but still in the list. Then we get an error like "Could not get a valid element rectangle from '{DivTag:}', since the element is no longer valid."

Is there a way to refresh the IList after clicking on an element?

User avatar
RobinHood42
Posts: 240
Joined: Fri Jan 09, 2015 3:24 pm

Re: IList; is it possible to refresh?

Post by RobinHood42 » Wed Jun 13, 2018 8:51 am

Hi agroenen,
But sometimes clicking on the element means deleting; so the element isn't on the screen anymore, but still in the list. Then we get an error like "Could not get a valid element rectangle from '{DivTag:}', since the element is no longer valid."
Can you please explain why this could be an issue. Assuming you have fetched 3 elements from your list element. Within the "foreach" you iterate over all of them. Element 1 is clicked and deleted, Element 2 and 3 are just clicked. So, you won't access Element 1 again. Therefore, it's irrelevant if the element was just click or deleted as well. :?:

Would be great if you could provide further information, that would help me to better understand your issue.

Cheers,
Robin :mrgreen:

ahoisl
Certified Professional
Certified Professional
Posts: 125
Joined: Fri Sep 07, 2007 8:16 am

Re: IList; is it possible to refresh?

Post by ahoisl » Wed Jun 13, 2018 10:13 am

agroenen wrote:Is there a way to refresh the IList after clicking on an element?
The only way to "refresh" elements is to search them anew, i.e. by retrieving them again from the repository (which does a search internally).

In your example, this could be achieved by setting the elementList variable again:
elementList = K2WItem.CreateAdapters<Unknown>();
Regards,
Alex
Ranorex Team

agroenen
Posts: 17
Joined: Thu Jun 09, 2016 3:18 pm

Re: IList; is it possible to refresh?

Post by agroenen » Thu Jun 14, 2018 3:06 pm

I managed to solve it by using a "while" loop, instead of foreach.
Error isn't coming up in this way.

@RobinHood: I can't explain it better, after the first element is deleted this error comes up. I thought that was maybe because it is still in the list, but I don't understand it either because it shouldn't matter.