Checkboxes are not getting checked for data driven inputs



  • 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();
    }
    


  • 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


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2