Handling Web tables

I want to edit the For Release loan but there is no error occured . Count of rows are captured in the table when I check it in the console. The results should be the Edit button in the row should be clickable. Kindly check my codes:

String ExpectedValue = ‘For Release’

WebDriver driver = DriverFactory.getWebDriver()

‘To locate table’
WebElement Table = driver.findElement(By.xpath(’//table/tbody’))

'To locate rows of table it will Capture all the rows available in the table ’
List Rows = Table.findElements(By.tagName(‘tr’))

println('No. of rows: ’ + Rows.size())

‘Find a matching text in a table and performing action’

‘Loop will execute for all the rows of the table’
table: for (int i = 0; i < Rows.size(); i++) {
‘To locate columns(cells) of that specific row’
List Cols = Rows.get(i).findElements(By.tagName(‘td’))

for (int j = 0; j < Cols.size(); j++) {
    'Verifying the expected text in the each cell'
    if (Cols.get(j).getText().equalsIgnoreCase(ExpectedValue)) {
        'To locate anchor in the expected value matched row to perform action'
        Cols.get(10).findElement(By.tagName('button')).click()

        break
    }
}

}

We will likely need the HTML that goes with your code to make an assessment, however, if you have already “found” your ExpectedValue, and you know your “button” is in the 11th column (counting starts from 0), then you do not need to “locate” it by tagname. You could just:
Cols.get(10).click()

Also

Also, if you know what column the “ExpectedValue” is in, then you don’t need to use the inner for loop, or, if you keep the inner for loop, then you should use, break table, not just break (you use the label, table, with your outer for loop), as you want to exit both inner and outer loops, when you click the button.

    'Verifying the expected text in the fourth column **without** inner for loop'
    if (Cols.get(4).getText().equalsIgnoreCase(ExpectedValue)) {
        'To locate anchor in the expected value matched row to perform action'
        Cols.get(10).click()

        break
    }
And maybe

Also, while testing your code, maybe put in some print statements so you can see if you have actually made your match.

for (int j = 0; j < Cols.size(); j++) {
   
    println("now we have ${Cols.get(j).getText()}")
    WebUI.comment("now we have ${Cols.get(j).getText()}")

    'Verifying the expected text in the each cell'
    if (Cols.get(j).getText().equalsIgnoreCase(ExpectedValue)) {
        'To locate anchor in the expected value matched row to perform action'
        Cols.get(10).click()

        break table
    }
}

I already fix the error , but I need first to scroll manually so that the edit button will work properly.The problem is Scroll are not working in my codes . kindly check my codes.

take note: the scroll bar will display if I scroll up and down using mouse or by using arrow down and arrow up

Manual mode:


Script mode
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys
import org.openqa.selenium.WebDriver as WebDriver
import org.openqa.selenium.chrome.ChromeDriver as ChromeDriver
import org.openqa.selenium.WebElement as WebElement
import org.openqa.selenium.By as By
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory

WebUI.openBrowser(‘’)

WebUI.maximizeWindow()

WebUI.setText(findTestObject(‘Page_Core Login/input_face_txtUsername’), ‘’)

WebUI.setEncryptedText(findTestObject(‘Page_Core Login/input_lock_outline_txtPassword’), ‘==’)

WebUI.sendKeys(findTestObject(‘Page_Core Login/input_lock_outline_txtPassword’), Keys.chord(Keys.ENTER))

WebUI.enhancedClick(findTestObject(‘Object Repository/Page_Core/p_Core Menu’))

WebUI.click(findTestObject(‘Object Repository/Page_Core/p_Loans’))

WebUI.click(findTestObject(‘Object Repository/Page_Core/span_Loan Master’))

WebUI.click(findTestObject(‘Page_Core/input_CID_txtSearchCIDLoan’))

WebUI.setText(findTestObject(‘Page_Core/input_CID_txtSearchCIDLoan’), ‘9203950’)

WebUI.sendKeys(findTestObject(‘Page_Core/input_CID_txtSearchCIDLoan’), Keys.chord(Keys.ENTER))

WebUI.delay(5)

WebUI.switchToFrame(findTestObject(‘Page_Core/iframe_Upload_ifrm1’), 60)

WebUI.scrollToElement(findTestObject(‘Page_Core/div_Particulars_ps-scrollbar-y’), 6000)

WebDriver driver = DriverFactory.getWebDriver()

‘Expected value from Table’
String ExpectedValue = ‘For Release’

‘To locate table’
WebElement Table = driver.findElement(By.xpath(‘//table/tbody’))

‘To locate rows of table it will Capture all the rows available in the table’
List rows_table = Table.findElements(By.tagName(‘tr’))

‘To calculate no of rows In table’
int rows_count = rows_table.size()

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

'To calculate no of columns(cells) In that specific row'
int columns_count = Columns_row.size()

println((('Number of cells In Row ' + row) + ' are ') + columns_count)

'Loop will execute till the last cell of that specific row'
for (int column = 0; column < columns_count; column++) {
    'It will retrieve text from each cell'
    String celltext = Columns_row.get(column).getText()

    println((((('Cell Value Of row number ' + row) + ' and column number ') + column) + ' Is ') + celltext)

    'Checking if Cell text is matching with the expected value'
    if (celltext == ExpectedValue) {
        'Getting the Country Name if cell text i.e Company name matches with Expected value'
        println((('Text present in row number ' + column) + ' is: ') + Columns_row.get(2).getText())

        String accountnum = Columns_row.get(0).getText()

        WebElement element = driver.findElement(By.xpath(('//*[@id="' + accountnum) + 'edit"]'))

        element.click()

        //Columns_row.get(10).click()
        //Columns_row.get(10).findElement(By.tagName('button')).click()
        /*WebElement button = driver.findElement(By.xpath('//button'))
		List<WebElement> actioncall = button.findElements(By.className('edit'))
		println (actioncall.)
		*/
        'After getting the Expected value from Table we will Terminate the loop'
        break
    }
}

}

elemements are the highlighted

Try using WebUI.scrollToElement() with the Edit button (not the scrollbar).