Test dynamically added inputs

I have a page that dynamically adds input elements. When an input added to the page using javascript, using findTestObject or By.xpath do not recognize the added input exists. Is there a way to test these?

For example, I load the page I have a form with table and one row.

<td><input name="code[]"></td>
<td><input name="qty[]"></td></tr>

When I change the input “code[]”, I have a jquery event “change” that will automatically add a new tr row to the table. As the user fills in the code fields, the page continues to add a new row for them to add more codes.

<td><input name="code[]" value="testcode1"></td>
<td><input name="qty[]" value="1"></td></tr><tr><td><input name="code[]"></td><td><input name="qty[]"></td></tr>

Using Katalon studio, when I set a value to “code[]” on the first row, send the TAB key, the page adds the new row, but when I try to access the second row, I get an error that the input can not be found.

WebUI.setText(findTestObject("parts/lookup/code1"), "test1")
WebUI.sendKeys(findTestObject("parts/lookup/code1"), Keys.chord(Keys.TAB))

When I try the following, I get the error the element can not be found. The input does exist after changing the code of the first line. It shows in the browser.

WebElement code2 = driver.findElement(By.xpath('//input[@name="code[]"][2]'))

to address element you can define it in OR following way:

bacic: xpath = '(//input[@name="code[]"])[${INDEX}]'

then in script you will use

WebUI.setText(findTestObject("parts/lookup/code",[('INDEX'):1]), "test1")WebUI.sendKeys(findTestObject("parts/lookup/code",[('INDEX'):1]), Keys.chord(Keys.TAB))WebUI.waitForElementClickable(findTestObject("parts/lookup/code",[('INDEX'):2]), 3)
WebUI.setText(findTestObject("parts/lookup/code",[('INDEX'):2]), "test2")
WebUI.sendKeys(findTestObject("parts/lookup/code",[('INDEX'):2]), Keys.chord(Keys.TAB))probably i miss something, i'm writing this from memory

Thank you, works perfect.

Minor syntax adjustment was needed, needed to remove the parentheses.

WebUI.setText(findTestObject("parts/lookup/code",['INDEX':2]), "test2")