forked from nbhat1/Selenium-JavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckCheckbox.java
More file actions
65 lines (47 loc) · 1.76 KB
/
Copy pathcheckCheckbox.java
File metadata and controls
65 lines (47 loc) · 1.76 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main.webdriver;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class checkCheckbox {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "\\GecoDriver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.investorszone.in");
// driver.findElement(By.xpath(".//*[@id='form1']/table/tbody/tr[3]/td/table/tbody/tr/td/label[1]/input")).getAttribute("checked");
List<WebElement> element = driver.findElements(By.name("login_type"));
int iSize = element.size();
System.out.println("Number of check boxes is " + iSize);
for (int i = 0; i < iSize; i++) {
String value = element.get(i).getAttribute("value");
System.out.println("Value of checkbox is " + value);
if (value.equals("INV")) {
String iCheck = element.get(i).getAttribute("checked");
System.out.println(iCheck); // check what is returning from
// getAttribute.
if (iCheck.equals("true")) {
System.out.println("Checkbox is already checked");
} else {
element.get(i).click();
}
} else if (value.equalsIgnoreCase("ADV")) {
boolean iCheck1 = element.get(i).isSelected();
if (iCheck1 == true) {
System.out.println("Checkbox is already checked");
} else {
element.get(i).click();
}
} else if (value.equalsIgnoreCase("ADM")) {
boolean iCheck2 = element.get(i).isSelected();
if (iCheck2 == true) {
System.out.println("Checkbox is already checked");
} else {
element.get(i).click();
}
}
}
driver.close();
}
}