forked from saranyaeaswaran/SeleniumTesting
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCheckBoxes.java
More file actions
31 lines (28 loc) · 1.13 KB
/
Copy pathCheckBoxes.java
File metadata and controls
31 lines (28 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package allTests;
import java.io.IOException;
import java.util.List;
import org.apache.http.client.ClientProtocolException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import utility.BaseTest;
import utility.FrameworkConstants;
public class CheckBoxes extends BaseTest{
@Test
public void test() throws InterruptedException, ClientProtocolException, IOException {
System.setProperty(FrameworkConstants.CHROME_DRIVER_KEY,FrameworkConstants.CHROME_DRIVER_PATH);
WebDriver driver = new ChromeDriver();
driver.findElement(By.xpath("//a[contains(text(),'Checkboxes')]")).click();
List<WebElement> checkboxElements = driver.findElements(By.cssSelector("#checkboxes input[type='checkbox']"));
//To select the checkbox which is not selected
System.out.println("no of checkboxes are : "+checkboxElements.size());
for(WebElement checkbox:checkboxElements) {
System.out.println("is this selected : "+checkbox.isSelected());
if(!checkbox.isSelected()) {
checkbox.click();
}
}
}
}