Results 1 to 3 of 3
  1. #1

    How can I check if a checkbox is created or not?

    I am testing a software that can open a dialog containing checkboxes that are either visible or does not load, depending on the state of the application.

    The code I am using looks like this:

    <font color="#666666">...
    var viewerSettings = mainProcess.GlobalSettings.settingsTabControl.view erTabPage.viewerSettings;
    var allowMultipleWindowsCheckbox = viewerSettings.enableMultipleWindows;
    var allowRemoteConnectionsCheckbox = viewerSettings.enableRTP;

    However, the "enableRTP" checkbox is not visible to the user in the cases where the user would not have any use for it, and when that occurs, it fails my test case.
    I have tried changing the last row into:

    <font color="#666666">var allowRemoteConnectionsCheckbox = viewerSettings.WinFormsObject("enableRTP");</font>

    However that always fails with the error message: "Unable to find the object WinFormsObject("enableRTP")", even when the checkbox is present.
    I have also tried to use the WaitWinFormsObject function, but the results are similar since it also never finds the checkbox.

    What is the correct way to look for these "sometimes missing" checkboxes?

    The program is written in C#, and I use JavaScript in TestComplete. I run TestComplete version 6.51.

  2. #2

    Re: How can I check if a checkbox is created or no


    This behavior is caused by .NET specifics: a window object is not created for a .NET control (a handle is not assigned to it) if the control is invisible and never was visible. To force creation of a window object, you just need to request the handle of the corresponding .NET object. If the handle does not exist, it is created along with the corresponding window object.

    The easiest way to do this is just to call the following script routine by passing the main form object to it:

    <font class="small">Code:</font><hr /><pre>
    function main()
    var obj = Sys.Process("&lt;process name&gt;").WinFormsObject("&lt;form name&gt;");

    function CheckHandles(obj)
    var tempvar = obj.Handle;
    for (var i = 0; i &lt; obj.Controls.Count; i++) {
    </pre><hr />
    Best regards,
    David - SmartBear Support

  3. #3

    Re: How can I check if a checkbox is created or no

    Thank you very much for the answer, David! It did solve my problem :-)

    In addition I also needed to change WinFormsObject("enableRTP") to WinFormsObject("_enableRTP"), as I noticed that viewerSettings.enableRTP.Name was "_enableRTP".



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
BetaSoft Inc.
All times are GMT -8. The time now is 03:53 PM.

Copyright BetaSoft Inc.