Tuesday, 22 August 2017

Code Example - Check Box Is Checked by List

package com.practiceCode;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.Test;

/**
* @Blog Name : Selenium Code Example
* @author Deepak Gupta
* @Created Date 23-08-2017
*
*/

public class VerifySelectTheCheckBoxFromList extends SuperTestNG {

@Test
public void testSelectTheCheckBoxFromList() throws InterruptedException {
try {
driver.get("http://only-testing-blog.blogspot.in/2013/09/testing.html");
List<WebElement> allOptions = driver.findElements(By.tagName("input"));
for (WebElement option : allOptions) {
if ("Boat".equals(option.getAttribute("value"))) {
if (!option.isSelected()) {
option.click();
System.out.println(option.getAttribute("value") + " - checkbox is checked");
break;
} else {
System.out.println(option.getAttribute("value") + " - checkbox is already checked");
}
}
}
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
}

}

}

No comments:

Post a Comment

Code Example - File Download By Robot Class In Firefox Browser

Exported from Notepad++ package com . practiceCode ; import java . awt . AWTException ; import java . awt . Robot ; import j...