How do you click on a checkbox from a list of checkboxes via Selenium/Webdriver in Java?

后端 未结 8 2068
北海茫月
北海茫月 2020-12-01 22:59

I\'m using Selenium 2 (Webdriver) for automating tests on a webpage. However I wonder if there is way to check checkbox from the list of checkboxes using webdriver framework

8条回答
  •  余生分开走
    2020-12-01 23:42

    Java, Clicking on multiple checkboxes at a time using the loop.

    **Sample Xpath :**
    
    CheckBox1 Xpath : //input[@class='mycheck' and @id='1']
    CheckBox2 Xpath : //input[@class='mycheck' and @id='2']
    

    Get all the elements checkbox using findelements:

    List WebElement ele = driver.findElements(By.xpath("//input[@class='mycheck']"));

    Make the Xpath as string by leaving the ID and assign the ID as i.

    for(int i=1; i<=ele.size(); i++) { driver.findElement(By.xpath("//input[@class='mycheck' and @id='" +  + i + "']")).click(); }
    

    i gets the value for every loop and the xpath matches the checkbox and click's it.

提交回复
热议问题