I am learning automation through Selenium (using Java programming language), and I am working on a test case. The last step in my case involves checking for the presence of a button an a page, by using findElement.By.xpath, and I have two versions of the step. With either version, my entire test case passes. However, the two versions each generate a different result by themselves. If I use the first version, with the int, I get "Write review button' does not exist" result. If I use the second version with the Boolean, I get "Write review button' exists!" Since the test case passes, and with the second version generating the 'button exists' result, the problem cannot be with the xpath, so the issue with the second version getting the wrong result must be in the logic, yet I cannot tell what it is.
I tried rerunning the case multiple times to see if the problem is a glitch, but same result. I tried finding similar problems online, but cannot find anything that shows exactly how my problem is wrong.
int i = driver.findElements(By.xpath("//ul[@class='comments_advices']")).size();
if (i > 0) { System.out.println("'Write review button' exists!"); }
else { System.out.println("'Write review button' does not exist :( ");
}
boolean reviewButtonPresent = driver.findElements(By.xpath("//ul[@class='comments_advices']")).size() > 0;
if (reviewButtonPresent = true) { System.out.println("'Write review button' exists!"); }
else { System.out.println("'Write review button' does not exist :( "); }