So I am new to katalon and what I am trying to accomplish is to set a a certain text in every text box of my table. I know that the text box tag name is an input and that its id has the next form:
//input[@id=‘vRESULTADOVALOR_0001’]
//input[@id=‘vRESULTADOVALOR_0002’]
//input[@id=‘vRESULTADOVALOR_0003’]
(…)
So I am trying to do something like this but it is not working: @Keyword
def getDynamicObjects(){
int number = 1
String dynamicId = ‘vRESULTADOVALOR_000’ + number
String xpath = ‘//div[@id="’ + dynamicId + ‘"]’
System.out.println(xpath)
number = number+1
}
As a first step I am trying to print the dynamic id for every column in the table. Then, find every text box using that dynamic id and set a certain text
Like this:
WebDriver driver = DriverFactory.getWebDriver()
WebElement Table = driver.findElement(By.id(‘Grid1ContainerDiv’))
List Rows = Table.findElements(By.tagName(‘tr’))
table: for (int i = 0; i < Rows.size(); i++) {
List Cols = Rows.get(i).findElements(By.tagName(‘td’))
for (int j = 0; j < Cols.size(); j++) {
CustomKeywords.‘keywordPrueba.CustomFunction.getDynamicObjects’()
break
}
}
Maybe my approach is not the correct one maybe my code is not correct. I am new to this and I am having some difficulties. If you have any suggestions I would be really happy
Once again, thanks for the answer.
It is still throwing the same id all the time which it is this one vRESULTADOVALOR_0001
Am I missing something? Is there a better solution for what I want to do?
In a different TC I do something like this…When I was trying a different solution I was trying to accomplish something similar but there is not a “set text” option for that case:
WebElement Table = driver.findElement(By.id(‘GRIDSDTORDENMUESTRASSTABLEWITHPAGINATIONBAR’))
List Rows = Table.findElements(By.tagName(‘tr’))
table: for (int i = 0; i < Rows.size(); i++) {
List Cols = Rows.get(i).findElements(By.tagName(‘td’))
for (int j = 0; j < Cols.size(); j++) {
if (Cols.get(j).getText().equalsIgnoreCase(ExpectedValue)) {
Cols.get(0).findElement(By.tagName(‘input’)).click()
break
}
}
}
Is there any other option or something else I can do?
Thank you very much, now it works ! For the next step I have to find each element on the table with that ID and then set the text. I will try to figure out how to do that and if anything goes wrong I will tell you.
So I managed myself to enter a certain text in every empty text box of the table. This took me some time to realize how to do.
Now the problem that I am not able to resolve is the next one…
Whenever I write in every text box I have to do something like this:
So the problem is that whenever it finishes setting every text box it continues with its search and I want to finish it. Clearly the break I have in my code is not working.
The error I have is like this:
Unable to find the element located by ‘By.xpath: //input[@id=‘vRESULTADOVALOR_0082’]’. Please recheck the objects properties to make sure the desired element is located.
Any ideas?
Thank you for the reply.
Do I need to write something extra cause my code is till trying to find an object is not there.
Although I added a new condition it still fails
Yes, even with the time out.
5: if (verifyElementPresent(toV, 30, STOP_ON_FAILURE))
2019-08-22 11:55:52.360 INFO c.k.k.c.webui.common.WebUiCommonHelper - Unable to find the element located by ‘By.xpath: //input[@id=‘vRESULTADOVALOR_0082’]’. Please recheck the objects properties to make sure the desired element is located.
I also added an else statement to the if but keeps failing
Hi,
I changed the time to 5 us you told me
I tried using optional and of course it continues but throwing its error every time it cannot find the object
I tried using STOP ON FAILURE and it gives me an error
I tried adding the break again and change it to different places to see what happens but it keeps searching
At this point I do not know what else to do
In the picture you can see the format of the table. As you can see the first space is blank but then that column has a textbox in every space.
This is like this because I have a certain object with sub objects and each one of this sub objects have the text box in the column "resultados’'.
This could change as I could have a table with more than one object and these with many sub objects.
So the row count gives you the number of cells (possibly one too many). You only need one loop looking for the input elements which have unique IDs which you are constructing in code.