Ranorex

Unhandled Exception in RxElementFindChild

 
Post new topic   Reply to topic    Ranorex Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
rodo



Joined: 08 Nov 2006
Posts: 10

PostPosted: Mon Nov 13, 2006 8:50 pm    Post subject: Unhandled Exception in RxElementFindChild
Hi,

i get an unhandled exception in RxElementFindChild function:

Code: click into code to enlarge

browser = RxFormFindTitle ("Microsoft Internet Explorer", MATCH_SUBSTRING, TRUE, 3000);
if (browser == 0)
{
   return FALSE;
}

if (!RxControlGetElement (browser, &elBrowser))
{
   return FALSE;
}

if (!RxElementFindChild (&elBrowser, 42, "Adresse", "Edit", &elAddress))
{
   return FALSE;
}


I used RanorexSpy to get role, name and classname.

I also tried the DumpElementTree function -> I got the exception in RxElementGetChild function.

What did I wrong / what can I do?

Thanks
rodo
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 05 Jul 2006
Posts: 351

PostPosted: Mon Nov 13, 2006 10:45 pm    Post subject:
Which version do you use? It was a known issue in the version 0.9.3.
(It happened only if a web page had hundreds of elements)

I coundn't reproduce the bug with 0.9.4, i tried it with a lot of web pages.
If you use 0.9.4 then please try the following:

1. The address edit box of the explorer is an edit control, you can find and use it also as follows:

Code: click into code to enlarge
browser = RxFormFindTitle ("Microsoft Internet Explorer", MATCH_SUBSTRING, TRUE, 3000);
if ( browser == 0 )
   return FALSE;

HWND addressBox = ::RxFormFindChildClassName(browser, "Edit");
if ( addressBox == 0 )
   return FALSE;

// Select the address edit box
::RxMouseClickControl(addressBox);
::RxControlSendKeys(addressBox, "http://www.google.com{ENTER}");

// Wait 3 seconds
::RxSleep(3000);

// Find the explorer control
HWND explorerControl = ::RxFormFindChildClassName(browser, "Internet Explorer_Server");
if ( explorerControl == 0 )
   return FALSE;

// Get the element of the IE control
ElementStruct elBrowser;
if (!RxControlGetElement (explorerControl, &elBrowser))
   return FALSE;

// Find a child element
ElementStruct elAddress;
if (!RxElementFindChild (&elBrowser, role, name, className, &element))
   return FALSE;
...

2. It can be a problem with RxElementFindChild if the browser is not ready with the web page.

3. It can be a bug in RanorexCore, can you save and send us the web page.
It's easier to find the bug if we can debug it.

Please inform us about the results, if it's a bug we would like to fix it for the next release.

Jenö Herget
Ranorex Team
Back to top
View user's profile Send private message Visit poster's website
rodo



Joined: 08 Nov 2006
Posts: 10

PostPosted: Tue Nov 14, 2006 12:50 am    Post subject:
Thank you for your reply.

Using HWND addressBox = ::RxFormFindChildClassName(browser, "Edit"); I can find addressbox, but there is still an unexpected exception in DumpElementTree function.

btw:
Actually I want to use a FindElementByValue function, but it does almost the same as DumpElementTree - it stores the first element, if the value is found instead of printing all elements. I get the exception in FindElementByValue and in DumpElementTree.
The elements I want to find are <input type="text" ... value="theValue"> - fields in a web page.

For debugging:
- I am using Ranorex 0.9.4
- the browser is ready with the web page
- it is an easy page (see below)
- the page is stored on local disk
- I am using Visual Studio .NET 2003
- I am using Win XP

Code: click into code to enlarge
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
</head>

<body>
    <div id="divID" style="width: 1024px; height: 768px"></div>
    <input type="text" name="name1" value="v1">
    <input type="text" name="name2" value="v2">
</body>

</html>


Please inform me, if you can find the reason for the exception.

Thanks
rodo
Back to top
View user's profile Send private message
rodo



Joined: 08 Nov 2006
Posts: 10

PostPosted: Tue Nov 14, 2006 1:30 am    Post subject:
I tried to do like this in DumpElementTree function:


Code: click into code to enlarge

...
try
{
    if (RxElementGetChild (pElem, index, &child))
    {
        DumpElementTree (&child, level, pFout);
    }
}
catch (...)
{
    // do nothing
}


The exception occures in element (pElem):
role = 10
name = ""
class = "Shell DocObject View"

But my element is not found (not printed) although RanorexSpy can find it.

brds
rodo
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 05 Jul 2006
Posts: 351

PostPosted: Tue Nov 14, 2006 2:05 am    Post subject:
I cannot reproduce this problem.
Here is my code:

Code: click into code to enlarge
#include "stdafx.h"
#include "RanorexCore.h"

#include "stdafx.h"
#include "RanorexCore.h"

void DumpElementTree(ElementStruct* pElement, int level)
{
  level++;
  int childCount = RxElementGetChildCount(pElement);
  for(int index=0;index<childCount;index++)
  {
    int childId=0;
    ElementStruct child;
    BOOL ret=RxElementGetChild(pElement, index, &child);
    if( ret == TRUE )
    {         
      for(int j=0;j<level;j++)
        printf("   ");
      printf("Index=%d Name=%s Role=%d Value=%s\n",
        index,child.Name,child.Role,RxElementGetValue(&child));
      DumpElementTree(&child,level);
    }
  }
}

BOOL _tmain(int argc, _TCHAR* argv[])
{
  // Finding form by class name and activate it (timeout=3000 msec)
  HWND browser = RxFormFindTitle("Microsoft Internet Explorer", MATCH_SUBSTRING, TRUE, 3000);
  if ( browser == 0 )
    return FALSE;

  // Find the explorer control
  HWND explorerControl = ::RxFormFindChildClassName(browser, "Internet Explorer_Server");
  if ( explorerControl == 0 )
    return FALSE;

  // Get the element of the IE control
  ElementStruct elBrowser;
  if (!RxControlGetElement (explorerControl, &elBrowser))
    return FALSE;
  DumpElementTree(&elBrowser, 0);

  return TRUE;
}


Please try this code and answer me the resuls, or send me your code.

Jenö Herget
Ranorex Team
Back to top
View user's profile Send private message Visit poster's website
rodo



Joined: 08 Nov 2006
Posts: 10

PostPosted: Tue Nov 14, 2006 9:37 pm    Post subject:
Now it works - thank you very much!

I tried this:
Code: click into code to enlarge

browser = RxFormFindTitle ("Microsoft Internet Explorer", MATCH_SUBSTRING, TRUE, 3000);
if (browser == 0)
{
   return FALSE;
}

if (!RxControlGetElement (browser, &elBrowser))
{
   return FALSE;
}

DumpElementTree (&elBrowser, 0);


Your code:
Code: click into code to enlarge

browser = RxFormFindTitle ("Microsoft Internet Explorer", MATCH_SUBSTRING, TRUE, 3000);
if (browser == 0)
{
   return FALSE;
}

HWND explorerControl = ::RxFormFindChildClassName(browser, "Internet Explorer_Server");
if (explorerControl == 0)
{
    return FALSE;
}

ElementStruct elBrowser;
if (!RxControlGetElement (explorerControl, &elBrowser))
{
    return FALSE;


DumpElementTree (&elBrowser, 0);


I do not really think this is the reason for the exception, because:
If I use my old code in a new application only with main-function (Ctrl-C, Ctrl-V) it works! But the same code in the other application does not work ...

Thank you once more for your help!
rodo
Back to top
View user's profile Send private message
rodo



Joined: 08 Nov 2006
Posts: 10

PostPosted: Tue Nov 14, 2006 10:04 pm    Post subject:
Now I found the reason for the problem:

I started a new thread using AfxBeginThread. The thread function calls another function to find all browser elements.

If I start the thread function directly (not in a new thread) it works!

Brds
rodo
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 05 Jul 2006
Posts: 351

PostPosted: Tue Nov 14, 2006 11:15 pm    Post subject:
Well, it's good news, thank you for your response.

Jenö Herget
Ranorex Team
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Ranorex Forum Index -> Bug Reports All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum