1
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class Test1 {

    public static void main(String[] args) throws InterruptedException {
          // TODO Auto-generated method stub
          System.setProperty("webdriver.chrome.driver","C://chromedriver_win32//chromedriver.exe");
          WebDriver driver= new ChromeDriver();
          driver.get("http://qaclickacademy.com/practice.php");
          List<WebElement> elements = driver.findElements(By.xpath("//input[@type= 'checkbox']"));
          System.out.println(Integer.toString(elements.size()));

          for(WebElement el:elements)
          {
                el.click();
          }
    }
}
  • Can you try by providing wait statement. – shanila Jan 19 at 12:11
  • I have used wait but still the program is going timeout exception. – Ashutosh Singh Jan 20 at 4:26
  • Code looks good, providing wait as suggested by Shanila should help, if not please share the exception stack. – Shamanth Jan 21 at 3:45
  • There could be a potential issue in the click statement as you are performing them in a loop. After performing the initial events, the state of the rest of the elements might be changing. So please be careful while performing webdriver events in loop. – Kshetra Mohan Prusty Jan 21 at 5:32
  • Probably your browser was updated and you need to update your webdriver? – Alexey R. Jan 21 at 12:30

Your Answer

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

Browse other questions tagged or ask your own question.