How to handle Web Tables


#1

This is a companion discussion topic for the original entry at https://docs.katalon.com/katalon-studio/docs/handle_web_tables.html

#2

Nice guide, but every page has a lot of tables and katalon starts to go throw every table. How to get the exactly needed table on the page?I tried the xpath from the table, but i got following massage:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {“method”:“xpath”,“selector”:"//*[@id=“mainlayoutsubsection”]/table[2]/tbody"}
How can i fix it?
Thanks,
Dmitry


#3

Let me preface with, very new to this, so please excuse my lack of knowledge.

I am trying to test the functionality of a web search tool by verifying the presence of text within rows of a single column within a table. For instance, I need to be able to enter “care” into the search, and verify that all rows of column 1 now display “care”. I will then need to repeat using a different search term for all rows in column 2, etc.

The closest resolution I’ve found is this statement, but I am unable to figure out how to specify a single column.


#4

I just want to get the row index, so i have tried to store it in a variable but it always give me Zero value.


#5

Sorry, it works when change the j to be i thanks.


#6

how to create an edit function in a table on the web without the expectation of a static value. but take a random data to edit?. Please help!


#7

How about if we want to delete data?


#8

Let’s say we need to delete a student record that has the graduation year of 2018, how?


#9

good morning first of all, can someone help me how to get the element of a list sent from a parameter and then that same element is selected?
I have this process that is capturing the element that sent it but does not select it, click on another element.

I hope your support thank you!
Captura|690x337


#10

[quote=“jquesquen21, post:9, topic:27225”]
690x337
[/quote]


#11

The tagName for the edit field is ‘a’ in this case. If you use the Katalon WebUI Spy and capture the ‘delete’ button you can see the specific tagName for the ‘delete’ object and in the code you can just change where it says:

Cols.get(4).findElement(By.tagName(‘a’)).click() to:

Cols.get(4).findElement(By.tagName(‘deleteTagName’)).click()

and it will click the delete object for you.


#12

i am working on application where i need to submit 100s of forms consists of 80-90 questions. every form will have different set of answers.

i have created switch statements for each question.

is there any way i can shorten the script, otherwise i have to create one switch statement for every question and one case statement for each answer.

Two excel sheets looks like for your reference as:

Question sheet (Static) looks like:
Question 1 Question 2
Answer A Answer A
Answer B Answer B
Answer C

Answer Sheet looks like:
Form Number Question1_Answer Question2_Answer
Form1 Answer B Answer B
Form2 Answer A Answer C
Form3 Answer A Answer A
(i iterated this through test suite data binding)
Switch statement I created as:

switch (Question1_Answer) {
case findTestData(‘Question_Sheet’).getValue(1, 1):
WebUI.click(findTestObject(‘A’))

    break
case findTestData('Question_Sheet').getValue(1, 2):
    WebUI.click(findTestObject('B'))

    break
default:
    break

}

switch (Question2_Answer) {
case findTestData(‘Question_Sheet’).getValue(2, 1):
Run_Time_Object = WebUI.modifyObjectProperty(findTestObject(‘A’), ‘id’, ‘equals’,
findTestData(‘Object ID Data’).getValue(3, 1), true)

    WebUI.click(Run_Time_Object)

    break
case findTestData('Question_Sheet').getValue(2, 2):
    Run_Time_Object = WebUI.modifyObjectProperty(findTestObject('A'), 'id', 'equals', 
        findTestData('Object ID Data').getValue(4, 1), true)

    WebUI.click(Run_Time_Object)

    break

case findTestData(‘Question_Sheet’).getValue(2, 3):
Run_Time_Object = WebUI.modifyObjectProperty(findTestObject(‘A’), ‘id’, ‘equals’,
findTestData(‘Object ID Data’).getValue(5, 1), true)

WebUI.click(Run_Time_Object)
default:
break
}

How can i create a loop so that i don’t need to create switch statement for each question?
Plz consider both columns and rows incremented…


#13

hello all, @h.bevis I wish if you can help me.
I’m working on the dynamics 365 web table, and I’m not able to select the first row in the web table. any idea how can solve this problem


#14

In the code above, you should be able to get the first row of a table by:

‘Loop will execute for all the rows of the table’
Loop:
for (int irow = 0; irow < rows_count; irow++)
{
‘To locate columns(cells) of that specific row’
Columns_row = rows_table.get(irow).findElements(By.tagName(‘td’));

However, I often put a wait statement, such as waitForElementVisible(To, 10) before trying to find the table element, such as:

‘delay until first row of table shows’
WebUI.waitForElementVisible(findTestObject(‘td_Table Row 1’), 10)
‘To locate table’
Table = driver.findElement(By.xpath("//table/tbody"));


#15

If I can suggest for you to put in either a println(table.get(j).getText()) or a WebUI.verifyMatch(table.get(j).getText(), ExpectedValue, false) after the FOR statement and before the IF statement to see what are the different values (the verifyMatch displays both texts in its log output). The difference may be the addition of only a period at the end, but that is enough to cause a failure.


#16

@dmitri.voronin Change the XPath so that, with an ID, you should use:

id("“mainlayoutsubsection”)/table[2]/tbody

something other than an ID, then use the double slashes at the start.

Also, it is often beneficial to put a waitForElementVisible to allow the table to form before checking the table elements.


#17

While this is a nice guide, I do take issue with the “store all elements in a list, then iterate and do action x” approach in general. This has two glaring issues:

1.) Depending on the size of the table, and the number of elements the script writer actually cares about validating/manipulating, then getting every element of a table and storing them in a list might be unnecessarily expensive. What if I only care about one particular cell at any given moment?

2.) An even bigger problem is that this approach has a high risk of throwing a StaleElementException. After you build a list of elements, if the DOM changes in any way (page reload, async js function, etc), then your list will almost certainly contain stale elements, in which case you would need to rebuild the list anyway to account for it (which is just problem #1 again).

In my opinion, it’s much more efficient as well as less risky to provide a locator that takes row/column indeces as arguments, and locate individual table elements at the moment they are needed. This way you are only every parsing the DOM for a single element, and the chance that that one element will become stale is drastically reduced.