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.
<form>
<table>
<tr>
<td><input name="code[]"></td>
<td><input name="qty[]"></td></tr>
</table>
</form>
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.
<form>
<table>
<tr>
<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>
</table>
</form>
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))
WebUI.delay(1)
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]'))