I know this is by design,
but is there any work around wherein which I can have it not invalidate itself?
I thought it would be the case of this thread: https://www.ranorex.com/forum/foreach-l ... t6285.html
But I cannot seem to get the Find function working
Any help?
Thanks
Foreach Loop invalidates after screen change
-
- Posts: 39
- Joined: Tue Aug 06, 2019 4:14 pm
Re: Foreach Loop invalidates after screen change
Hi,
Could you please post your code, so we can eventually suggest a solution? Usually, it should be enough to simply reset the list, with new instance of looped object. But without seeing exact code, it's impossible to tell what you should do.
Could you please post your code, so we can eventually suggest a solution? Usually, it should be enough to simply reset the list, with new instance of looped object. But without seeing exact code, it's impossible to tell what you should do.
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
-
- Posts: 39
- Joined: Tue Aug 06, 2019 4:14 pm
Re: Foreach Loop invalidates after screen change
Code: Select all
IList<Ranorex.TdTag> AuthCells = repo.LinkedScreens.TableCellInfo.Find<Ranorex.TdTag>("");
int counter = AuthCells.Count;
Report.Info("Cells in list " + counter.ToString());
if(counter>0)
{
for(int i = 1; i <=counter; i++)
{
AuthCells = repo.LinkedScreens.TableCell.Find<Ranorex.TdTag>();
foreach(Ranorex.TdTag Cell in AuthCells)
{
Validate.Exists(Cell);
if(Cell.InnerText != null)
{
Report.Info(Cell.ToString());
//Do Stuff (it's basically if contains this, do this, else if contains that, do that)
}
}
}
What I want to do is access these rows if they exist and carry out the workflow based on the text inside the summary cell, I know a more simple solution exists but this would demand hardcoding some stuff in, which I am not fond of.
Re: Foreach Loop invalidates after screen change
Hi,
So if I understand it right, after you "do stuff", the AuthCells is no longer valid, right? In this case, it should be enough to simply refill the AuthCells with new (refreshed) content?...
So if I understand it right, after you "do stuff", the AuthCells is no longer valid, right? In this case, it should be enough to simply refill the AuthCells with new (refreshed) content?...
Code: Select all
IList<Ranorex.TdTag> AuthCells = repo.LinkedScreens.TableCellInfo.Find<Ranorex.TdTag>("");
int counter = AuthCells.Count;
Report.Info("Cells in list " + counter.ToString());
if(counter>0)
{
for(int i = 1; i <=counter; i++)
{
AuthCells = repo.LinkedScreens.TableCell.Find<Ranorex.TdTag>();
foreach(Ranorex.TdTag Cell in AuthCells)
{
Validate.Exists(Cell);
if(Cell.InnerText != null)
{
Report.Info(Cell.ToString());
//Do Stuff (it's basically if contains this, do this, else if contains that, do that)
AuthCells = repo.LinkedScreens.TableCell.Find<Ranorex.TdTag>();
}
}
}
}
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
-
- Posts: 39
- Joined: Tue Aug 06, 2019 4:14 pm
Re: Foreach Loop invalidates after screen change
My god I'm an idiot, thank you so much this should have been obvious to me 

Re: Foreach Loop invalidates after screen change
Hi, no you are not. I found it "the hard way" too in the past 

Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration