Katalon Studio v5.8 - It's time for the all-new API testing experience
Sampath Kumar
Katalon Apprentice
06/12/2018

Help Need in For Loops

Hi,

I tried the below code, it is working fine as expected

WebUI.executeJavaScript('grid.scrollRowIntoView(0,false);', []);
WebElement dom = WebUI.executeJavaScript('return grid.getCellNode(0,0);', []);
println(dom.getText());

When I try to loop over on the above code as 

for (int i = 0; i<rowCount; i++) {
WebUI.executeJavaScript('grid.scrollRowIntoView(i,false);', []);
WebElement dom = WebUI.executeJavaScript('return grid.getCellNode(i,0);', []);
println(dom.getText());
}

I am getting null point exception.

Can anyone please help me in this regard.

Any help would be much appreciated.

Thanks,
Sampath.
Upvote
Quote

Comments

  • Rahul
    Katalon Ambassador
    06/13/2018
    Hi

    put your code in try catch block and see for what value of i it is throwing NPE

    try{
    for (int i = 0; i<rowCount; i++) {
    WebUI.executeJavaScript('grid.scrollRowIntoView(i,false);', []);
    WebElement dom = WebUI.executeJavaScript('return grid.getCellNode(i,0);', []);
    println(dom.getText());
    }catch(Exception e){
    }

    My guess is that, for a value of i following statement is returning null

    WebElement dom = WebUI.executeJavaScript('return grid.getCellNode(i,0);', []);

    here dom might be nulll
    and that's why dom.getText() is throwing NPE
    Upvote
    Quote
  • Sampath Kumar
    Katalon Apprentice
    06/13/2018
    Hi Rahul,

    Thanks for the reply, I was able to sort out the issue by replacing i with '+i+' in my code.

    Regards,
    Sampath
    Upvote
    Quote
Sign In or Register to comment.