Jump to content

IF statement is not working for me


Recommended Posts


 		String msg =row.getCell(5).toString();
	    System.out.println("msg " + msg);
    	 if (shouldLoginNo.trim() == "Yes"){
	       System.out.println("msg " + msg);

Its not printing the IF message. 

msg is coming from excel spreadsheet. It is getting the value "Yes" just fine. I added trim method but it is still not printing IF message. 

If I hard code value like this and it works. It tells me something is wrong when it reads value from excel. 

			        shouldLoginNo = "Yes";

How can I print the msg inside the IF block? Thanks!

Edited by newcoder1010
Link to comment
Share on other sites

Print the variable to see if it contains the value you expected it to have.

System.out.println("*" + shouldLoginNo + "*");


Link to comment
Share on other sites

I am doing selenium web driver testing and to read data from excel, I am using apache POI. 

Again reading data from excel, I have no problem. When it compares in the IF statement, I have problem. 

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
File file =    new File("C://Tek_AllSites.xls");
// Open the Excel file
FileInputStream fis = new FileInputStream(file);
// Access the required test data sheet
HSSFWorkbook wb = new HSSFWorkbook(fis);
HSSFSheet sheet = wb.getSheet("AllSites");
int TotalRow;
int TotalCol;
String pageTitle = "";
TotalRow = sheet.getLastRowNum();
System.out.println("Total row " + TotalRow);
TotalCol = sheet.getRow(0).getLastCellNum();
HSSFRow headerRow = sheet.getRow(0);
String result = "";
for(int count = 1;count<=TotalRow;count++){
    HSSFRow row = sheet.getRow(count);
	String shouldLoginNo =row.getCell(5).toString();
    System.out.println("pageTitle " + pageTitle);
	System.out.println("*" + shouldLoginNo + "*"); // Printig Yes just fine
	if (shouldLoginNo.trim() == "Yes"){
	    System.out.println("*" + shouldLoginNo + "*");  // Not printing here


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...