How to locate a Checkbox item in Datadog synthetic test with Terraform

109 views Asked by At

I'm building a Datadog's Synthetic Browser test with Terraform, but I'm facing issues to address this HTML element: <input type="checkbox" name="payrollInstructionIds" value="957e1f96-377d-4cec-a815-e6ec0e52402d">

The step I'm trying to do is a click on that checkbox. But, should be considered that the page have 9 checkboxes, and all of them have the same 'type' and 'name' properties. Only 'value' changes.

I have tried with these options, but the test always fails at that step, saying that the element couldn't be located. Option 1:

  browser_step {
    name = "Click checkbox: Reg. Salary Pay"
    type = "click"
    params {
      element_user_locator {
        fail_test_on_cannot_locate = "true"
        value {
          type  = "css"
          value = "input[value='957e1f96-377d-4cec-a815-e6ec0e52402d']"
        }
      }
    }
  }

Option 2:

  browser_step {
    name = "Click checkbox: Reg. Salary Pay"
    type = "click"
    params {
      element_user_locator {
        fail_test_on_cannot_locate = "true"
        value {
          type  = "css"
          value = "input[type='checkbox',value='957e1f96-377d-4cec-a815-e6ec0e52402d']"
        }
      }
    }
  }

Option 3:

  browser_step {
    name = "Click checkbox: Reg. Salary Pay"
    type = "click"
    params {
      element_user_locator {
        fail_test_on_cannot_locate = "true"
        value {
          type  = "css"
          value = "input[type='checkbox']"
        }
      }
    }
  }

All the three options give me this result on the Datadog's GUI: Error Cannot locate element.

Anyone knows how to do it?

Expectation: The synthetic browser test is able to click the checkbox and continue with the next test's steps.

1

There are 1 answers

0
Lenin Carrasco On BEST ANSWER

For anyone facing this problem, the solutions is putting all the element's attributes in separated brackets.

For the case presented in the question, the solution would be:

    name = "Click checkbox: Reg. Salary Pay"
    type = "click"
    params {
      element_user_locator {
        fail_test_on_cannot_locate = "true"
        value {
          type  = "css"
          value = "input[type='checkbox'][name='payrollInstructionIds'][value='957e1f96-377d-4cec-a815-e6ec0e52402d']"
        }
      }
    }
  }