Forum Discussion

Bea's avatar
Bea
New Contributor
5 years ago
Solved

Missing checkbox

Hi all,

 

I'm testing a webpage in Chrome. I recorded the flow, but when I played back, TestComplete could not find the checkbox. I tried to select the object with drag the target and point and fix tools but they not marked the checkbox exactly (just the whole field with a name).

I find the checkbox in html and saw the xpath but I dont know how to put manually into the test. 

If you have any idea to fix my first test, please contact me šŸ™‚ Thanks!

 

 

 

7 Replies

  • Hi,

     

    Can you post here a screenshot and the html markup of the problematic check-box and its parent element?

     

  • Hi,

     

    is that ok?

    Yes, it is. šŸ™‚

    Actually, this is what I expected to see.

    As you can see from the markup, there is no actual check-box there, but just a span element styled to look like check-box, with no text and presentation role. Such elements are excluded from the objects hierarchy in TestComplete as documented here: https://support.smartbear.com/testcomplete/docs/app-testing/web/general/object-identification/tree-model-elements.html.

    Unless you can solve this problem with your Development, the following workaround can be used:

    -- Find the element that works as a label for this pseudo check-box ('Megtekintes' as per your screenshot);

    -- Try to click, say, 5 pixels to the left from label's left border

    Pseudocode:

    var label = page.FindChild('value', 'Megtekintes', 50);

    label.Click(label.Left - 5, label.Top + label.Height / 2);

     

    OR

    -- use the .FindChildByXPath() method to find the span element itself.

    Note, that in this case, as this span element is absent in TestComplete's Objects Tree, as a search result you will get not TestComplete's object, but native DOM one. In order to click this object, native .click() method must be used (note small 'c' at the beginning):

    var checkbox = page.FindChildByXPath(<XPath>);

    checkbox.click();

     

    It is expected that the value of some attribute of the span element will change after the click.

    You may use the native .getAttribute() method (if I remember it correctly) to get the value of this property and determine the state of this pseudo check-box (checked or unchecked).

     

    Hope this will help.

     

    • Bea's avatar
      Bea
      New Contributor

      Hi,

       

      sorry about the stupid questions. 

       

      I recorded again the test and tried to click like you said. Where can I use the pseudo that you wrote?

       

      I set the operation FindChildByXPath with a Megtekintes value (SearchInFrames 1). 

      I send you a picture about Object Browser.

       

      Can you write step by step how can I set the missing parts? 

       

      Thaks a lot! 

      • AlexKaras's avatar
        AlexKaras
        Icon for Champion Level 3 rankChampion Level 3

        Hi,

         

        Where can I use the pseudo that you wrote?

        The suggested code should be inserted where the recorded click is done. (Post recorded script or screenshot of the keyword test if you like me to point you exact place.)

         

        Can you write step by step how can I set the missing parts?

        Assuming screenshots that you already posted (and JScript language), I would start with this:

        -- Code snippet:

        var cbox = page.FindChildByXPath('//SPAN[contains(@id, '-checkboxEl')];

        if (cbox != null)

          cbox.click();

        else

          Log.Error('check-box for Megtekintes label was not found');

         

        -- Paste this code snippet instead the line where the click on check-box was recorded and try to execute.

         

         

        P.S. Alternative code snippet:

        var cboxLabel = page.FindChild(['ObjectIdentifier', 'contentText'], ['appcheckcolumn_textInnerEl', 'Megtekin*'], 100);

        if (cboxLabel.Exists)

          cboxLabel.Click(cboxLabel.Left - 5, cboxLabel.Top + cboxLabel.Height / 2);

        else

          Log.Error('Megtekintes label for check-box was not found');