How to refresh the table after it is updated

Hi Team,

Am trying to create a value in table by calling another test case, after one element is updated it should go to next column in the same row. But it is not happening :frowning: and getting stale element error.

Please help me on this. At column[3] am getting the error

ListlistOfAllTextTables = driver.findElements(By.className(‘fieldgrid-block-grid’))

System.out.println(‘Table count’:(listOfAllTextTables).size())

WebElement useTable=listOfAllTextTables[1]

ListrowsTable = useTable.findElements(By.tagName(‘tr’))

System.out.println(‘Table Data’:(useTable).getText())

int rows_count = rowsTable.size()

for (int i = 0; i < rows_count; i++) {

/*System.out.println((('Row Number: ' + i) + ' | text: ') + (rowsTable[i]).getText())*/

List<WebElement>columns = (rowsTable[i]).findElements(By.tagName('td'))

int columns_count = columns.size()

/*for (int j = 0; j < columns_count; j++) {

			System.out.println('Column Data':(columns[j]).getText())*/
	
	WebElement inputTag = (columns[0]).findElement(By.tagName('input'))
	
	System.out.println('found row':(columns[0]).getText())
	
	if (inputTag.getAttribute('checked') != null) {
		(columns[1]).click()
		(columns[1]).click()
					
		WebElement roleColumn = useTable.findElement(By.className('icon-menu'))
  
		  roleColumn.click()
		  
		  WebUI.callTestCase(findTestCase('Test Cases/Base Structure/Common/Selection in pop selector grid'), [('SEARCHSTRING') : 'Test_Engineer'],
			  FailureHandling.STOP_ON_FAILURE)
		
		  				  (columns[3]).click()
			  
			  
 WebUI.callTestCase(findTestCase('Test Cases/Base Structure/Common/Selection in pop selector grid'), [('SEARCHSTRING') : GlobalVariable.jtestersp],
	 FailureHandling.STOP_ON_FAILURE)
		  }
					
	}

I won’t get into the negatives of doing it this way, but how about:

listOfAllTextTables = driver.findElements(By.className('fieldgrid-block-grid'))

System.out.println('Table count':listOfAllTextTables.size())

WebElement useTable = listOfAllTextTables[1]

ListrowsTable = useTable.findElements(By.tagName('tr'))

System.out.println('Table Data':(useTable).getText())

int rows_count = rowsTable.size()

for (int i = 0; i < rows_count; i++) {

	List<WebElement> columns = (rowsTable[i]).findElements(By.tagName('td'))

	int columns_count = columns.size()

	WebElement inputTag = (columns[0]).findElement(By.tagName('input'))
	
	System.out.println('found row':(columns[0]).getText())
	
	if (inputTag.getAttribute('checked') != null) {
		(columns[1]).click()
		(columns[1]).click()  // why twice ???
					
		WebElement roleColumn = useTable.findElement(By.className('icon-menu'))
  
		roleColumn.click()
		  
		WebUI.callTestCase(findTestCase('Test Cases/Base Structure/Common/Selection in pop selector grid'), [('SEARCHSTRING') : 'Test_Engineer'], FailureHandling.STOP_ON_FAILURE)
		
		columns = (rowsTable[i]).findElements(By.tagName('td'))  // recheck the row
		(columns[3]).click()
	  
 		WebUI.callTestCase(findTestCase('Test Cases/Base Structure/Common/Selection in pop selector grid'), [('SEARCHSTRING') : GlobalVariable.jtestersp], FailureHandling.STOP_ON_FAILURE)
	}				
}

Thanks for the response Grylion,
(columns[1]).click()
(columns[1]).click() this i have used twice because it should click the same column twice to open popup.
columns = (rowsTable[i]).findElements(By.tagName(‘td’)) // recheck the row
(columns[3]).click() - In this row is correct but after updating data in the column 1 table has to refresh. This should be done by function itseems but am not aware :frowning:

I am not sure what do you mean by this?

The concern with “staleElementException” is that the element may have changed since you “read” it last, so the idea is to refresh the columns variable with the below code:
columns = (rowsTable[i]).findElements(By.tagName('td')) // recheck the row

and then you should not get the exception.

Does the additional code I suggested work or not?

Thanks Grylion,

I have tried below code and it worked

System.out.println(‘Entering data for column 1’)
enterDataInTable(1, driver, “Test_Engineer”)
System.out.println(‘Entering data for column 3’)
enterDataInTable(3, driver, “JTESTERSP”)
//enterDataInTable(rowToedit[3], 0, 3, driver, “1”)
System.out.println(‘Entered data for column’)

WebUI.callTestCase(findTestCase('Base Structure/Common/Logout'), [:], FailureHandling.STOP_ON_FAILURE)

//enterDataInTable(rowsInTable1[1], 0, 4, driver, "4")

def enterDataInTable(int count, WebDriver driver, String fieldText)
{
	List<WebElement> listOfAllTextTables = driver.findElements(By.className('fieldgrid-block-grid'))
	System.out.println('Table count':(listOfAllTextTables).size())
	
	WebElement useTable=listOfAllTextTables[1]
	
	List<WebElement>rowToedit = useTable.findElements(By.tagName('tr'))
	
	System.out.println('Table Data':(useTable).getText())

int rows_count = rowToedit.size()

for (int i = 0; i < rows_count; i++) {

	List<WebElement>columns = (rowToedit[i]).findElements(By.tagName('td'))

int columns_count = columns.size()

	WebElement inputTag = (columns[0]).findElement(By.tagName('input'))
	
	System.out.println('found Column':(columns[0]).getText())
	if (inputTag.getAttribute('checked') != null) {
		(columns[count]).click()
		
		if (count==1) {
		(columns[count]).click()
					
		WebElement roleColumn = useTable.findElement(By.className('icon-menu'))
  
		  roleColumn.click()}
		  
		  WebUI.callTestCase(findTestCase('Test Cases/Base Structure/Common/Selection in pop selector grid'), [('SEARCHSTRING') : fieldText],
			  FailureHandling.STOP_ON_FAILURE)
		  break
		  }
		
}
System.out.println('This function has ended')
}