Page 1 of 1
Unhandled Exception in RxElementFindChild
Posted: Mon Nov 13, 2006 7:50 pm
by rodo
Hi,
i get an unhandled exception in
RxElementFindChild function:
Code: Select all
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
Posted: Mon Nov 13, 2006 9:45 pm
by webops
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: Select all
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
Posted: Mon Nov 13, 2006 11:50 pm
by rodo
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: Select all
<!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
Posted: Tue Nov 14, 2006 12:30 am
by rodo
I tried to do like this in
DumpElementTree function:
Code: Select all
...
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
Posted: Tue Nov 14, 2006 1:05 am
by webops
I cannot reproduce this problem.
Here is my code:
Code: Select all
#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
Posted: Tue Nov 14, 2006 8:37 pm
by rodo
Now it works - thank you very much!
I tried this:
Code: Select all
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: Select all
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
Posted: Tue Nov 14, 2006 9:04 pm
by rodo
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
Posted: Tue Nov 14, 2006 10:15 pm
by webops
Well, it's good news, thank you for your response.
Jenö Herget
Ranorex Team