Multiple Upload Buttons, Katalon not recognising the second and third

Hi all
It’s me again with many questions. Firstly thanks to all that have helped me previously.

So previously, I have a problem that I could not upload a file, but thankfully @Russ_Thomas and @grylion54 helped tremendously there. It now works to upload a file. The problem was an iframe that I wasn’t taking into account.

However that worked only for the first upload button. In my first screenshot attached, I show that I have three Upload buttons.

However with the following script, I manage to click on the first Upload Button (Latest Academic Results), which brings up a modal on which I can upload a file, but it doesn’t work for the 2nd and 3rd button. With all the following information, does anyone have an idea of how I could still click on the 2nd and 3rd button, to bring up the modal because right now it throws an error.

// Clicking the First Button
WebUI.click(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - Student Enrolment/latestAcademicResults_Button'))

// Upload file
WebUI.uploadFile(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - Student Enrolment/choose_files'), 'C:\\Users\\tomgb\\OneDrive\\Pictures\\3D image 1.jpg')

// Clicking the Second Button
WebUI.click(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - Student Enrolment/idDocument_Button'))

// Upload file
WebUI.uploadFile(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - Student Enrolment/choose_files'), 'C:\\Users\\tomgb\\OneDrive\\Pictures\\3D image 1.jpg')

// Clicking the Third Button
WebUI.click(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - Student Enrolment/nationalSeniorCertificate_Button'))

// Upload file
WebUI.uploadFile(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - Student Enrolment/choose_files'), 'C:\\Users\\tomgb\\OneDrive\\Pictures\\3D image 1.jpg')

Now The uploadFile objects are the same on all modals (I checked) however after the first file is uploaded for the first button, Katalon fails and pulls up an error (2nd, 3rd, and 4th screenshot attachment)

So I got the xpath for each of the buttons, in order from top to bottom, from right-clicking the HTML element for the button, and saying Copy xpath:
Top: //*[@id=“Latest Academic Results”]/td[2]/button
Middle: //*[@id=“ID Document or Passport”]/td[2]/button
Bottom: //*[@id=“National Senior Certificate (NSC)”]/td[2]/button

And here is the HTML element for each button, in order from top to bottom:
Top: <button onclick="qc.pA('SupportingDocuments','uploadSupportingDocument', 'QClickEvent', 'Latest Academic Results');" class="btn btn-danger fullWidth" type="button">Upload</button>
Middle: <button onclick="qc.pA('SupportingDocuments','uploadSupportingDocument', 'QClickEvent', 'ID Document or Passport');" class="btn btn-danger fullWidth" type="button">Upload</button>
Bottom: <button onclick="qc.pA('SupportingDocuments','uploadSupportingDocument', 'QClickEvent', 'National Senior Certificate (NSC)');" class="btn btn-danger fullWidth" type="button">Upload</button>

For the sake of complete information, the 5th screenshot shows the HTML, of which the highlighted element is the element for the top button.

Screenshot 1

Screenshot 2

Screenshot 3

Screenshot 4

Screenshot 5

You probably need to put wait’s in between your uploads. Based on the error you got, it looks like your xpaths are fine, but that there was a timing issue when trying to click the second button. What happens to the page after you upload the first file (does it reload the page, do certain elements get updated, etc.)? A quick fix might be:

// Clicking the First Button
WebUI.click(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - Student Enrolment/latestAcademicResults_Button'))

// Upload file
WebUI.uploadFile(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - Student Enrolment/choose_files'), 'C:\\Users\\tomgb\\OneDrive\\Pictures\\3D image 1.jpg')

// Wait...
WebUI.waitForElementClickable(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - Student Enrolment/idDocument_Button'))

// Clicking the Second Button
WebUI.click(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - Student Enrolment/idDocument_Button'))

// Upload file
WebUI.uploadFile(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - Student Enrolment/choose_files'), 'C:\\Users\\tomgb\\OneDrive\\Pictures\\3D image 1.jpg')

// Wait...
WebUI.waitForElementClickable(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - Student Enrolment/nationalSeniorCertificate_Button'))

// Clicking the Third Button
WebUI.click(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - Student Enrolment/nationalSeniorCertificate_Button'))

// Upload file
WebUI.uploadFile(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - Student Enrolment/choose_files'), 'C:\\Users\\tomgb\\OneDrive\\Pictures\\3D image 1.jpg')

If you don’t mind a suggestion on another topic, not to do with your “uploadFile” concern

I notice on your selectOptionByValue() methods that you are setting your third parameter as true. Setting true for selectOptionByValue() or selectionOptionByLabel() means that you want to use RegEx. RegEx is for wild card replacement of letters and/or optional syntax of characters. With your value as “1” or “2”, there is no need for RegEx. I would suggest that you set the boolean to false. And your test scripts may speed up too. Also, in other instances, you may encounter weird situations when you have true and a RegEx character that you want to have as a normal comparison.