Search code examples
xpathautomationcodeception

2 forms - Credit Card and Checking Account - 2 identical xpaths for one checkbox - automation will not click the checkbox


here is the xpath I am using

//tr[@id = 'inputSavePaymentAccounts']/descendant::input[@type = 'checkbox' and @name = 'payAck' and @tabindex = '10'

here is how I can get it to check the checkbox

jQuery('.payAck').prop('checked', true)

here is the checking account html that is inside an iframe

<tr id="inputSavePaymentAccounts" class="savePaymentAccounts" style="display: table-row;">
<td class="addCCLabel" style="padding-top: 15px;">Save this Payment Method</td>
<td style="padding-top: 15px;">
    <input class="payAck" type="checkbox" onchange="friendlyNameShow()" name="payAck" tabindex="10">
    </td>
</tr>

here is the credit card html that is inside the same iframe

<tr id="inputSavePaymentAccounts" class="savePaymentAccounts" style="display: table-row;">
<td class="addCCLabel" style="padding-top: 15px;">Save this Payment Method</td>
<td style="padding-top: 15px;">
    <input class="payAck" type="checkbox" onchange="friendlyNameShow()" name="payAck" tabindex="25">
    </td>
</tr>

The main issue is that when i use:

jQuery('.payAck').prop('checked', true)

it checkmarks the checkbox however, at the time the checkbox is checked I am suppose to see a text box display, which is not happening with the above jquery. I was hoping the execution of xpath would solve this

see these for a more clearer picture
image of checkbox http://prnt.sc/c12b1p
image of checkbox when it is checked with text box displaying (need this to happen) http://prnt.sc/c12b7q


Solution

  • First of all, I would recommend you remove the inline javascript. Your primary selector in this case is a class and the class is assigned to 2 elements (at least from what I see in your example). When you check the checkbox using jQuery with the class selector, it is going to trigger all the elements that belong to that class and I don't think that is what you intend to do. Also, using click() will work, but that will cause friendlyNameShow() to be called twice and you will need to check the state of the checkbox since you are not explicitly checking/un-checking it. Try using and Id instead.