Problem with TryFindSingle

Class library usage, coding and language questions.
User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Problem with TryFindSingle

Post by Aracknid » Tue Aug 28, 2012 4:19 pm

This one is baffling me...

I have a frame tag stored in an object, and I also have the WebBrowser stored in an object. I'm looking for an Anchor within the frame. The frame is in the WebBrowser. And the Anchor is in the Frame.

PathToAnchor = ".//a[@id='MyID']"

If I do this code, it works (finds the anchor):
if not BrowserObj.TryFindSingle(PathToAnchor,DelayTime,MyAnchor) then
    'Failed to find the anchor. handle it
end if
But if I do this, it does NOT work (it give a runtime error)
if not FrameObj.TryFindSingle(PathToAnchor,DelayTime,MyAnchor) then
    'Failed to find the anchor. handle it
end if
The error I get is "Value cannot be null.Parameter name: adapter"

However (and this is the confusing part), if instead I change the code to this, it DOES work and I have no idea why. I've used TryFindSingle many times before in my code and never run into this...
MyAnchor = FrameObj.FindSingle(PathToAnchor,DelayTime)
'Works. MyAnchor is found...
Any thoughts?

Using Ranorex 3.3.1 and VS2012

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

Re: Problem with TryFindSingle

Post by artur_gadomski » Wed Aug 29, 2012 6:44 am

Do you declare MyAnchor the same way in both cases?

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: Problem with TryFindSingle

Post by Aracknid » Wed Aug 29, 2012 2:37 pm

Yes, MyAnchor is decalred as this:
Dim MyAnchor as Ranorex.ATag = Nothing
And what I'm doing is putting a breakpoint at the line where I try to use the TryFindSingle. When I get to it and hit F8 to step into the line, It throws me into my catch. I can then move it to the line of code where I do the FindSingle and it works (which is only there for debugging purposes).

Aracknid

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

Re: Problem with TryFindSingle

Post by artur_gadomski » Thu Aug 30, 2012 6:39 am

Well the only other object is FrameObj. Are you sure that it exists? Although it would be a rather confusing error message. Can you post full exception?

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: Problem with TryFindSingle

Post by Aracknid » Wed Nov 07, 2012 3:31 pm

Sorry it has taken a while to post a reply. I stumbled across this issue again just recently, and this time I think I figured out why it happens.

As per the above example, the reason it seems to fail is because of the ways I've decalred the items.

The FrameObj has been decalred as follows:
Dim FrameObj As Ranorex.Core.Element = Nothing
And MyAnchor as:
Dim MyAnchor as Ranorex.ATag = Nothing
When FrameObj is a valid object, the code in the example does not work. However, if I change the declaration of MyAnchor to:
Dim MyAnchor as Ranorex.Core.Element = Nothing
It does work.

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

Re: Problem with TryFindSingle

Post by artur_gadomski » Thu Nov 08, 2012 7:58 am

Seems like it can not find a ATag but can find an Element. How does your PathToAnchor look like?

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: Problem with TryFindSingle

Post by Aracknid » Thu Nov 08, 2012 3:20 pm

PathToAnchor = ".//a[@id='MyID']"

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

Re: Problem with TryFindSingle

Post by artur_gadomski » Fri Nov 09, 2012 7:38 am

I've got nothing... other than generic did you try to increase timeout and could you post bigger piece of code and/or snapshot. Sorry.