3
    System.setProperty("webdriver.chrome.driver", "C:\\Users\\srajendran\\Documents\\chromedriver.exe");
    WebDriver driver=new ChromeDriver();

    driver.get("http://qaclickacademy.com/practice.php");
    driver.manage().window().maximize();
    WebElement Radio = driver.findElement(By.xpath("//input[@value='radio1']"));
    Radio.click();
    Thread.sleep(2000);

    WebElement Radio2 = driver.findElement(By.xpath("//input[@value='radio2']"));
    Radio2.click();
    Thread.sleep(2000);
    Assert.assertEquals(driver.findElements(By.xpath("//input[@class='radioButton']")).size(), "3");
    System.out.println(driver.findElements(By.xpath("//input[@class='radioButton']")).size());
    Thread.sleep(2000);

    WebElement Checkb1= driver.findElement(By.xpath("//input[@value='option1']"));
    Checkb1.click();


    WebElement Checkb2= driver.findElement(By.xpath("//input[@value='option2']"));
    Checkb2.click();

   System.out.println(driver.findElements(By.xpath("//input[@type='checkbox']")).size());

1 Answer 1

8

Hi size() returns integer and you are comparing with string

You can use the size() method of java. util. ArrayList to find the length or size of ArrayList in Java. The size() method returns an integer equal to a number of elements present in the array list. https://www.java67.com/2016/07/how-to-find-length-size-of-arraylist-in-java.html

So the fix would be to change "3" to 3:

Assert.assertEquals(driver.findElements(By.xpath("//input[@class='radioButton']")).size(), 3);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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