Forum Discussion

Bea's avatar
Bea
New Contributor
5 years ago

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!

 

 

 

  • Hi,

     

    Thank you for the screenshot. What is reported to test log if you execute this test?

    From what I see, I can make these notes:

    1. The operation (Call Object Method) where you are searching for the web element using .FindChildByXPath() method returns the object been found. In order to use this object later, you must create keyword test variable and assign this variable a value returned by .FindChildByXPath(). Use the Set Variable Value operation with the Last Operation Result option value for the Mode parameter.

    2. Sample code snippet that I provided previously assumed that the tested web page is referenced via the page variable, but in your keyword test the tested web page is referenced as pageIts20. So the code must be adjusted correspondingly.

    3. Use either approach with .FindChildByXPath() or the code that was provided as the alternative. Alternative code may be used as is (with corrected reference to page). If you decide to use .FindChildByXPath(), then you should assign the result of the search to variable (as mentioned in point 1) and then use this variable to call method .click() (note small first 'c') of the found object.

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

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

     

    • Bea's avatar
      Bea
      New Contributor

      Hi Alex,

      is that ok? 

      Thanks 

       

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    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
        Champion 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');