Problems with array and with if

Hello,

I have several questions about a script.

1- In the String Data = new String [numDatos] section there are times that the part of numDatos is removed from the script execution. Do you know why?

String ExpectedValue = Jobcode

String Texto_Max_Pags = WebUI.getText(findTestObject('Object Repository/Assign/max_pags'))

int Max_Pags = Integer.parseInt(Texto_Max_Pags)

WebDriver driver = DriverFactory.getWebDriver()

WebElement Table = driver.findElement(By.xpath('//table/tbody'))

List<WebElement> Rows = Table.findElements(By.tagName('tr'))

for (int p = 1; p <= Max_Pags; p++) {
    println('El número de filas es: ' + Rows.size)

    for (int i = 1; i < Rows.size(); i++) {

        List<WebElement> Cols = Rows.get(i).findElements(By.tagName('td'))
		
		int numDatos = Cols.size - 3
		
		String[] Datos = new String[numDatos]

        if (Cols.get(10).getText().equalsIgnoreCase(ExpectedValue)) {
			
            println('El número de columnas es: ' + Cols.size)

            for (int j = 2; j < (Cols.size() - 1); j++) {
				      
				(Datos[(j - 2)]) = Cols.get(j).getText()

                println(((('Datos ' + (j - 2)) + '-') + ' ') + (Datos[(j - 2)]))
            }
            
            System.out.println(Datos)

            System.out.println(('Resultado: \'' + (Datos[8])) + '\'')

            GlobalVariable.DatosTabla = Datos
        }
        
        if (i == (Rows.size - 1)) {
            WebUI.click(findTestObject('Object Repository/Assign/flecha_dch'))
        }
    }
    
    i = 1

    driver = DriverFactory.getWebDriver()

    Table = driver.findElement(By.xpath('//table/tbody'))

    Rows = Table.findElements(By.tagName('tr'))
}

2- When I do an execution, if’s that do not enter take a long time to finish. Is that because of a configuration problem?

1.) First off, in the below code:

int numDatos = Cols.size - 3

you should be calling the size() method, like this:

int numDatos = Cols.size() - 3

Second, what you are doing here is risky. What if, hypothetically, Cols.size() returns 0 or 1 or 2 or 3? Then when you go to create the array, you could potentially trying be creating an array of negative/zero size. If I had a better idea of what you were trying to accomplish, I could likely give you a more robust solution.

2.) Use the waitForElementVisible() method instead, where you can provide a smaller timeOut argument: