Clicking on a OptionTag invalidates parent SelectTag

Class library usage, coding and language questions.
markvanraalte
Posts: 13
Joined: Thu Apr 15, 2010 4:34 pm

Clicking on a OptionTag invalidates parent SelectTag

Post by markvanraalte » Sun Jul 25, 2010 11:49 am

Hi Team,

I am trying to loop through all the OptionTag elements in a SelectTag (a drop down menu).
I can loop through all the values but it seems that as soon as I click on an option tag, (which refreshes part of the web page), the Select Tag menu becomes invalid. I can no longer click on it. I have checked the 'valid' property and sure enough - after clicking on the child option tag, the SelectTag becomes invalid. This is despite the fact that the RanorexPath has not changed. I have confirmed this with Ranorex spy.

Code as follows:

SelectTag _stVenues = "/dom[@caption~'Venue Page']//form/select[@id='sltc']";

foreach (OptionTag _otVenue in _stVenues.Find<OptionTag>("./option"))
{
// Expand Menu
_stVenues.Click();

// Click on current item
ListItem _option = "/container[@caption='selectbox']/listitem[@accessiblename='" + _otVenue.InnerText + "']";
txtMessage.Text = "Current option item is: " + _otVenue.InnerText + "; Select Tag is: " + (_stVenues.Valid ? "VALID" : "NOT VALID"); txtMessage.Refresh();
_option.Click(); // Navigates to a new URL (refreshes the lowerhalf of web page)
Ranorex.Core.Delay.Seconds(2);
// !no longer valid - next iteration of loop will fail
txtMessage.Text = "Current option item is: " + _otVenue.InnerText + "; Select Tag is: " + (_stVenues.Valid ? "VALID" : "NOT VALID"); txtMessage.Refresh();
}


I seem to have reacquire the SelectTag to make it valid again by executing;
SelectTag _tmp_stVenues = "<same selectTag path>";
(Of course my loop object is still invalid)

1. Any suggestions to stop the object begin invalidated
2. Clicking on each item goes to a new URL which refreshes the lower half of the web page. Is it possible to find the URLs so I can navigate to them in turn without having to click on each item?

Thanks for your help?

Mark

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Clicking on a OptionTag invalidates parent SelectTag

Post by artur_gadomski » Mon Jul 26, 2010 6:36 am

I have noticed that ranorex objects (in my case repository objects) loose reference to whatever they're pointing to when it's window is closed. I do the same thing you noticed. Reassign the object everytime I leave the window.

EDIT: Disabling cashing in parent window might help.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Clicking on a OptionTag invalidates parent SelectTag

Post by Support Team » Mon Jul 26, 2010 3:37 pm

artur_gadomski wrote:I have noticed that ranorex objects (in my case repository objects) loose reference to whatever they're pointing to when it's window is closed
This behavior is by design. The elements you get when you search for a RanoreXPath are linked to the actual UI elements in the application. Once the UI elements are gone, the Ranorex element becomes invalid and you need to get a new instance of the the element by searching for the RanoreXPath again.
markvanraalte wrote:Any suggestions to stop the object begin invalidated
Use the Ranorex Repository. The repository performs this behavior implicitly, i.e. it searches for the RanoreXPath again when the element becomes invalid and returns a new instance (if one exists for the specified path).

Regards,
Alex
Ranorex Team
.
Image

markvanraalte
Posts: 13
Joined: Thu Apr 15, 2010 4:34 pm

Re: Clicking on a OptionTag invalidates parent SelectTag

Post by markvanraalte » Tue Jul 27, 2010 3:58 pm

Thanks, but I'm not sure if using the repository is a very satisfactory solution for me, because I tend to create a lot of objects with code by using the Find() function, FindChildren() and also manually building up XPath strings. Can you suggest another way to check? Can I check to see if an XPath is valid without invoking an exception?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Clicking on a OptionTag invalidates parent SelectTag

Post by Support Team » Tue Jul 27, 2010 7:38 pm

You can check whether an element/adapter is still valid using the Valid property.
And you can search for a RanoreXPath without an exception to be raised by using the Find or TryFindSingle methods:
Button button;
bool found = Host.Local.TryFindSingle<Button>("pathToButton", out button);

List list = ...;
IList<ListItem> foundItems = list.Find<ListItem>("pathToListItems");
Regards,
Alex
Ranorex Team
.
Image