Page 1 of 1

Retaining the UI variable between two operations

Posted: Tue Aug 09, 2011 9:20 am
by vengaishiva
Hi,
I am having a form and the form contains a text box. First I initalize a Text variable with the rx path of this textbox. And am getting the text in it correctly.
Next am closing the form through automation. Do some functions and open the same form again. I want the text value again. But this time instead of initializing a new textbox variable, am using the same variable which i had initialized earlier. But it is not giving me the text value in it. It always returns me empty. Kindly help. Am giving you the code here.

Form f = @"/form[@name='Copy']";
Text t = @"/form[@name='Copy']/text[@automationid='PART_Notional']";
Console.WriteLine(t.TextValue); //This line prints the correct value '20'
f.Close();
//Do some operations and open the same form again
Console.WriteLine(t.TextValue); //This line always prints empty even though it has value in it.

My question is, how to get the value in the Textvariable t, between closing the form and opening the form. If the form which contains the control is closed once, is it not possible to use the same control after opening the form?
Kindly Help

Regards,
Siva R S

Re: Retaining the UI variable between two operations

Posted: Tue Aug 09, 2011 3:52 pm
by Ciege
Your t variable is not actually a variable of the text value on the form but a pointer to the element on the form. Thus, when the form is open .TextValue has a value in it and when the form is closed (i.e. the element no longer exists) the variable no longer points to a valid element and .TextValue is now empty.

You should set a string variable to the value of .TextValue before closing the form. Like:

Code: Select all

string MyString = t.TextValue;
Then after you close the form, use the variable MyString to get at the stored value.

Re: Retaining the UI variable between two operations

Posted: Tue Aug 09, 2011 3:57 pm
by vengaishiva
Hi,
Thanks for the reply. Totally agree with your point. But my question is, i want to get the text value after closing the form, doing some operations and again opening the same form. Now after opening the form, the value need not be the same. It may vary. I want to get the data for my verification process.

My question is, is it possible for the text variable 't' to be valid after the close and opening of the form?

Thanks
Siva R S

Re: Retaining the UI variable between two operations

Posted: Tue Aug 09, 2011 4:03 pm
by Ciege
But my question is, i want to get the text value after closing the form, doing some operations and again opening the same form.
So, if you get a reference to an element on the form (t), close the form (t is now invalid) and open the form again, you are asking if t should now contain the new value on the new iteration of the exact same form or the original value of t from the original iteration on the form?

Re: Retaining the UI variable between two operations

Posted: Tue Aug 09, 2011 4:19 pm
by vengaishiva
Hi,
t should now contain the new value on the new iteration of the exact same form is what am expecting.

Re: Retaining the UI variable between two operations

Posted: Tue Aug 09, 2011 4:25 pm
by Ciege
Well, if I understand it properly, after the form closes t is pointing to the original element still not the new element. Maybe since Ranorex already found t it will not try and find the new version of t since it already has that information cached... (maybe...) Or it could be that the new element on the new form is technically different since the original element path has been destroyed by your f.close...

I would suggest that after you close the form the open the form again, have Ranorex find the element t again on the new form so that you know you have a valid xpath to that new element.

Re: Retaining the UI variable between two operations

Posted: Tue Aug 09, 2011 4:33 pm
by vengaishiva
Thanks Ciege. I will re-instantiate the variable t with the same path, after closing and opening the form. :wink: