0

The checkboxes are not getting checked when they are within the if...else if statements. But its working perfectly without if..else if. The code is skipping the if blocks. I couldn't find the reason of skipping. Below is the code snippet-

String manual = sht1.getRow(i).getCell(5).getStringCellValue();
String automation = sht1.getRow(i).getCell(6).getStringCellValue();

if (manual == "Y" && automation == "N"){
   WebElement prof_manual = driver.findElement(By.xpath("/html/body/div[4]/div[1]/div/div[2]/div[1]/div/div[6]/div/form/table/tbody/tr[6]/td[2]/span[1]/input"));
   prof_manual.click();
}
else if (manual == "N" && automation == "Y"){
   WebElement prof_auto = driver.findElement(By.xpath("/html/body/div[4]/div[1]/div/div[2]/div[1]/div/div[6]/div/form/table/tbody/tr[6]/td[2]/span[2]/input"));
   prof_auto.click();
}
else if (manual == "Y" && automation == "Y"){
   WebElement prof_manual = driver.findElement(By.xpath("/html/body/div[4]/div[1]/div/div[2]/div[1]/div/div[6]/div/form/table/tbody/tr[6]/td[2]/span[1]/input"));
   prof_manual.click();
   WebElement prof_auto = driver.findElement(By.xpath("/html/body/div[4]/div[1]/div/div[2]/div[1]/div/div[6]/div/form/table/tbody/tr[6]/td[2]/span[2]/input"));
   prof_auto.click();
}
  • 2
    String comparison is made with equals() rather than == operator. What programming language is this? What are the values of String manual and String automation? – Aulis Ronkainen Nov 5 '18 at 18:36
  • Yes, I got it Aulis Ronkainen. Thanks much !! – Appan Singha Roy Nov 6 '18 at 4:40
  • In the spirit of StackExchange @AulisRonkainen write it in the answers and you should get the answered flag to it. – Saša Zejnilović Nov 6 '18 at 5:49
0

You are using '==' operator to compare Strings. This usually doesn't do what you want it to do. It compares object references, not the values of the Strings. You should use equals() method instead, which compares the actual values of the Strings, and then you are able to run the code inside the ifs.

For more information see: https://stackoverflow.com/questions/7520432/what-is-the-difference-between-vs-equals-in-java

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.