How to skip row when for loop is executing and row is emptyHow does the Java 'for each' loop work?How do I time a method's execution in Java?Iterating through a Collection, avoiding ConcurrentModificationException when removing objects in a loopHow can I create an executable JAR with dependencies using Maven?How do I break out of nested loops in Java?Unable to read excel if cell/column has drop down list enabled for Selenium webdriver TestNGBlank rows is skipped while reading data from the excel sheetHow to extract double int value from excel sheet using seleniumHow to get column values from an excel using only column name?how can i use TestNg assertion method in for loop

Bookshelves: the intruder

Have the writers and actors of Game Of Thrones responded to its poor reception?

Does science define life as "beginning at conception"?

What's is the easiest way to purchase a stock and hold it

Why is so much ransomware breakable?

Why does snapping your fingers activate the Infinity Gauntlet?

How to convince boss to spend notice period on documentation instead of new projects

"File type Zip archive (application/zip) is not supported" when opening a .pdf file

How could the B-29 bomber back up under its own power?

Isn't Kirchhoff's junction law a violation of conservation of charge?

How do we explain the use of a software on a math paper?

Bash Array of Word-Splitting Headaches

Warped chessboard

Novel where a cube cooled below absolute zero makes a hole in reality

What were the "pills" that were added to solid waste in Apollo 7?

How do I unravel apparent recursion in an edef statement?

Bash - Execute two commands and get exit status 1 if first fails

Easier way to draw a filled ellipse with top edge dashed and bottom edge solid?

If you attack a Tarrasque while swallowed, what AC do you need to beat to hit it?

Was murdering a slave illegal in American slavery, and if so, what punishments were given for it?

FIFO data structure in pure C

Why didn't Daenerys' advisers suggest assassinating Cersei?

Why is python script running in background consuming 100 % CPU?

Can't think of a good word or term to describe not feeling or thinking



How to skip row when for loop is executing and row is empty


How does the Java 'for each' loop work?How do I time a method's execution in Java?Iterating through a Collection, avoiding ConcurrentModificationException when removing objects in a loopHow can I create an executable JAR with dependencies using Maven?How do I break out of nested loops in Java?Unable to read excel if cell/column has drop down list enabled for Selenium webdriver TestNGBlank rows is skipped while reading data from the excel sheetHow to extract double int value from excel sheet using seleniumHow to get column values from an excel using only column name?how can i use TestNg assertion method in for loop






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have 2 excel sheets, I am comparing cell values using the testNg Assertion. Following are the values in sheet1 and sheet2, after david, I have an empty row in both the sheets, my script is failing since row 3 is blank and it's not going to row 4?



Sheet1 Sheet2

sachin sachin
david david

winter winter


I have written following code:-



int rowCount = xlib.getRowCount("Sheet1");

for (int i = 0; i<=rowCount;i++)

String compair1= xlib.getExcelData("Sheet1", i, 0);
System.out.println(compair1);
String compair2=xlib.getExcelData("Sheet2", i, 0);
System.out.println(compair2);
Assert.assertEquals(compair1, compair2);
System.out.println("compared successfully");



Need correct code, it should skip the 3rd row since it has blank value and move to 4th row and compare and pass the script.










share|improve this question
























  • Add check for the value compair1 or compair2 to be null, and if so don't Assert.

    – VSB
    Mar 23 at 18:15











  • You could just clean up your data... or grab all data and filter out empties.

    – JeffC
    Mar 25 at 21:57

















0















I have 2 excel sheets, I am comparing cell values using the testNg Assertion. Following are the values in sheet1 and sheet2, after david, I have an empty row in both the sheets, my script is failing since row 3 is blank and it's not going to row 4?



Sheet1 Sheet2

sachin sachin
david david

winter winter


I have written following code:-



int rowCount = xlib.getRowCount("Sheet1");

for (int i = 0; i<=rowCount;i++)

String compair1= xlib.getExcelData("Sheet1", i, 0);
System.out.println(compair1);
String compair2=xlib.getExcelData("Sheet2", i, 0);
System.out.println(compair2);
Assert.assertEquals(compair1, compair2);
System.out.println("compared successfully");



Need correct code, it should skip the 3rd row since it has blank value and move to 4th row and compare and pass the script.










share|improve this question
























  • Add check for the value compair1 or compair2 to be null, and if so don't Assert.

    – VSB
    Mar 23 at 18:15











  • You could just clean up your data... or grab all data and filter out empties.

    – JeffC
    Mar 25 at 21:57













0












0








0








I have 2 excel sheets, I am comparing cell values using the testNg Assertion. Following are the values in sheet1 and sheet2, after david, I have an empty row in both the sheets, my script is failing since row 3 is blank and it's not going to row 4?



Sheet1 Sheet2

sachin sachin
david david

winter winter


I have written following code:-



int rowCount = xlib.getRowCount("Sheet1");

for (int i = 0; i<=rowCount;i++)

String compair1= xlib.getExcelData("Sheet1", i, 0);
System.out.println(compair1);
String compair2=xlib.getExcelData("Sheet2", i, 0);
System.out.println(compair2);
Assert.assertEquals(compair1, compair2);
System.out.println("compared successfully");



Need correct code, it should skip the 3rd row since it has blank value and move to 4th row and compare and pass the script.










share|improve this question
















I have 2 excel sheets, I am comparing cell values using the testNg Assertion. Following are the values in sheet1 and sheet2, after david, I have an empty row in both the sheets, my script is failing since row 3 is blank and it's not going to row 4?



Sheet1 Sheet2

sachin sachin
david david

winter winter


I have written following code:-



int rowCount = xlib.getRowCount("Sheet1");

for (int i = 0; i<=rowCount;i++)

String compair1= xlib.getExcelData("Sheet1", i, 0);
System.out.println(compair1);
String compair2=xlib.getExcelData("Sheet2", i, 0);
System.out.println(compair2);
Assert.assertEquals(compair1, compair2);
System.out.println("compared successfully");



Need correct code, it should skip the 3rd row since it has blank value and move to 4th row and compare and pass the script.







java selenium






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 22:11









TheChubbyPanda

98511025




98511025










asked Mar 23 at 18:12









Lokesh B CLokesh B C

31




31












  • Add check for the value compair1 or compair2 to be null, and if so don't Assert.

    – VSB
    Mar 23 at 18:15











  • You could just clean up your data... or grab all data and filter out empties.

    – JeffC
    Mar 25 at 21:57

















  • Add check for the value compair1 or compair2 to be null, and if so don't Assert.

    – VSB
    Mar 23 at 18:15











  • You could just clean up your data... or grab all data and filter out empties.

    – JeffC
    Mar 25 at 21:57
















Add check for the value compair1 or compair2 to be null, and if so don't Assert.

– VSB
Mar 23 at 18:15





Add check for the value compair1 or compair2 to be null, and if so don't Assert.

– VSB
Mar 23 at 18:15













You could just clean up your data... or grab all data and filter out empties.

– JeffC
Mar 25 at 21:57





You could just clean up your data... or grab all data and filter out empties.

– JeffC
Mar 25 at 21:57












2 Answers
2






active

oldest

votes


















2














Use the continue statement.



int rowCount = xlib.getRowCount("Sheet1");

for (int i = 0; i<=rowCount;i++)

try
String compair1= xlib.getExcelData("Sheet1", i, 0);
System.out.println(compair1);
String compair2=xlib.getExcelData("Sheet2", i, 0);
System.out.println(compair2);
Assert.assertEquals(compair1, compair2);
System.out.println("compared successfully");
catch (Exception e)
continue;







share|improve this answer























  • Thanks that helped !!! But I have another challenge, I am having some rows with date format (mm-dd-yyyy) , it is failing to read that entry , it is saying text cell value as numeric, is there any way, I can read the date format and compare both the sheets or should I need to change the date format in the excel itself?

    – Lokesh B C
    Mar 23 at 18:39











  • That counts as another question and hence should be separate from this one. Please ask a separate question regarding this issue.

    – TheChubbyPanda
    Mar 23 at 18:42












  • @LokeshBC Please mark this question as solved.

    – TheChubbyPanda
    Mar 23 at 20:52


















0














You could set the loop from i to i<=2.
Following that loop, do another loop from i=4 to i <=rowCount.






share|improve this answer























  • this is one example, but actually I have to 50 rows, some are blank in the middle, I cannot use many loops instead can I get something if statement stating if row is blank skip and move to next row like that?

    – Lokesh B C
    Mar 23 at 18:21











  • Oh in that case, TheChubbyPanda's answer should be what you're looking for.

    – TheButterWorm
    Mar 23 at 18:23











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55316899%2fhow-to-skip-row-when-for-loop-is-executing-and-row-is-empty%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Use the continue statement.



int rowCount = xlib.getRowCount("Sheet1");

for (int i = 0; i<=rowCount;i++)

try
String compair1= xlib.getExcelData("Sheet1", i, 0);
System.out.println(compair1);
String compair2=xlib.getExcelData("Sheet2", i, 0);
System.out.println(compair2);
Assert.assertEquals(compair1, compair2);
System.out.println("compared successfully");
catch (Exception e)
continue;







share|improve this answer























  • Thanks that helped !!! But I have another challenge, I am having some rows with date format (mm-dd-yyyy) , it is failing to read that entry , it is saying text cell value as numeric, is there any way, I can read the date format and compare both the sheets or should I need to change the date format in the excel itself?

    – Lokesh B C
    Mar 23 at 18:39











  • That counts as another question and hence should be separate from this one. Please ask a separate question regarding this issue.

    – TheChubbyPanda
    Mar 23 at 18:42












  • @LokeshBC Please mark this question as solved.

    – TheChubbyPanda
    Mar 23 at 20:52















2














Use the continue statement.



int rowCount = xlib.getRowCount("Sheet1");

for (int i = 0; i<=rowCount;i++)

try
String compair1= xlib.getExcelData("Sheet1", i, 0);
System.out.println(compair1);
String compair2=xlib.getExcelData("Sheet2", i, 0);
System.out.println(compair2);
Assert.assertEquals(compair1, compair2);
System.out.println("compared successfully");
catch (Exception e)
continue;







share|improve this answer























  • Thanks that helped !!! But I have another challenge, I am having some rows with date format (mm-dd-yyyy) , it is failing to read that entry , it is saying text cell value as numeric, is there any way, I can read the date format and compare both the sheets or should I need to change the date format in the excel itself?

    – Lokesh B C
    Mar 23 at 18:39











  • That counts as another question and hence should be separate from this one. Please ask a separate question regarding this issue.

    – TheChubbyPanda
    Mar 23 at 18:42












  • @LokeshBC Please mark this question as solved.

    – TheChubbyPanda
    Mar 23 at 20:52













2












2








2







Use the continue statement.



int rowCount = xlib.getRowCount("Sheet1");

for (int i = 0; i<=rowCount;i++)

try
String compair1= xlib.getExcelData("Sheet1", i, 0);
System.out.println(compair1);
String compair2=xlib.getExcelData("Sheet2", i, 0);
System.out.println(compair2);
Assert.assertEquals(compair1, compair2);
System.out.println("compared successfully");
catch (Exception e)
continue;







share|improve this answer













Use the continue statement.



int rowCount = xlib.getRowCount("Sheet1");

for (int i = 0; i<=rowCount;i++)

try
String compair1= xlib.getExcelData("Sheet1", i, 0);
System.out.println(compair1);
String compair2=xlib.getExcelData("Sheet2", i, 0);
System.out.println(compair2);
Assert.assertEquals(compair1, compair2);
System.out.println("compared successfully");
catch (Exception e)
continue;








share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 23 at 18:20









TheChubbyPandaTheChubbyPanda

98511025




98511025












  • Thanks that helped !!! But I have another challenge, I am having some rows with date format (mm-dd-yyyy) , it is failing to read that entry , it is saying text cell value as numeric, is there any way, I can read the date format and compare both the sheets or should I need to change the date format in the excel itself?

    – Lokesh B C
    Mar 23 at 18:39











  • That counts as another question and hence should be separate from this one. Please ask a separate question regarding this issue.

    – TheChubbyPanda
    Mar 23 at 18:42












  • @LokeshBC Please mark this question as solved.

    – TheChubbyPanda
    Mar 23 at 20:52

















  • Thanks that helped !!! But I have another challenge, I am having some rows with date format (mm-dd-yyyy) , it is failing to read that entry , it is saying text cell value as numeric, is there any way, I can read the date format and compare both the sheets or should I need to change the date format in the excel itself?

    – Lokesh B C
    Mar 23 at 18:39











  • That counts as another question and hence should be separate from this one. Please ask a separate question regarding this issue.

    – TheChubbyPanda
    Mar 23 at 18:42












  • @LokeshBC Please mark this question as solved.

    – TheChubbyPanda
    Mar 23 at 20:52
















Thanks that helped !!! But I have another challenge, I am having some rows with date format (mm-dd-yyyy) , it is failing to read that entry , it is saying text cell value as numeric, is there any way, I can read the date format and compare both the sheets or should I need to change the date format in the excel itself?

– Lokesh B C
Mar 23 at 18:39





Thanks that helped !!! But I have another challenge, I am having some rows with date format (mm-dd-yyyy) , it is failing to read that entry , it is saying text cell value as numeric, is there any way, I can read the date format and compare both the sheets or should I need to change the date format in the excel itself?

– Lokesh B C
Mar 23 at 18:39













That counts as another question and hence should be separate from this one. Please ask a separate question regarding this issue.

– TheChubbyPanda
Mar 23 at 18:42






That counts as another question and hence should be separate from this one. Please ask a separate question regarding this issue.

– TheChubbyPanda
Mar 23 at 18:42














@LokeshBC Please mark this question as solved.

– TheChubbyPanda
Mar 23 at 20:52





@LokeshBC Please mark this question as solved.

– TheChubbyPanda
Mar 23 at 20:52













0














You could set the loop from i to i<=2.
Following that loop, do another loop from i=4 to i <=rowCount.






share|improve this answer























  • this is one example, but actually I have to 50 rows, some are blank in the middle, I cannot use many loops instead can I get something if statement stating if row is blank skip and move to next row like that?

    – Lokesh B C
    Mar 23 at 18:21











  • Oh in that case, TheChubbyPanda's answer should be what you're looking for.

    – TheButterWorm
    Mar 23 at 18:23















0














You could set the loop from i to i<=2.
Following that loop, do another loop from i=4 to i <=rowCount.






share|improve this answer























  • this is one example, but actually I have to 50 rows, some are blank in the middle, I cannot use many loops instead can I get something if statement stating if row is blank skip and move to next row like that?

    – Lokesh B C
    Mar 23 at 18:21











  • Oh in that case, TheChubbyPanda's answer should be what you're looking for.

    – TheButterWorm
    Mar 23 at 18:23













0












0








0







You could set the loop from i to i<=2.
Following that loop, do another loop from i=4 to i <=rowCount.






share|improve this answer













You could set the loop from i to i<=2.
Following that loop, do another loop from i=4 to i <=rowCount.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 23 at 18:15









TheButterWormTheButterWorm

156




156












  • this is one example, but actually I have to 50 rows, some are blank in the middle, I cannot use many loops instead can I get something if statement stating if row is blank skip and move to next row like that?

    – Lokesh B C
    Mar 23 at 18:21











  • Oh in that case, TheChubbyPanda's answer should be what you're looking for.

    – TheButterWorm
    Mar 23 at 18:23

















  • this is one example, but actually I have to 50 rows, some are blank in the middle, I cannot use many loops instead can I get something if statement stating if row is blank skip and move to next row like that?

    – Lokesh B C
    Mar 23 at 18:21











  • Oh in that case, TheChubbyPanda's answer should be what you're looking for.

    – TheButterWorm
    Mar 23 at 18:23
















this is one example, but actually I have to 50 rows, some are blank in the middle, I cannot use many loops instead can I get something if statement stating if row is blank skip and move to next row like that?

– Lokesh B C
Mar 23 at 18:21





this is one example, but actually I have to 50 rows, some are blank in the middle, I cannot use many loops instead can I get something if statement stating if row is blank skip and move to next row like that?

– Lokesh B C
Mar 23 at 18:21













Oh in that case, TheChubbyPanda's answer should be what you're looking for.

– TheButterWorm
Mar 23 at 18:23





Oh in that case, TheChubbyPanda's answer should be what you're looking for.

– TheButterWorm
Mar 23 at 18:23

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55316899%2fhow-to-skip-row-when-for-loop-is-executing-and-row-is-empty%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현