I'm using Selenium WebDriver, and want to tick a specific HTML checkbox based on the value of a column called MovieType
in an Excel file. The checkbox should be ticked if the column contains Yes
and unticked if it contains No
.
The HTML code looks like this:
<input type="checkbox" onclick="trigger functionA();" tabindex="4" value="vnow" name="movie_Type"/>
How can I set the value of the checkbox if my Excel file contains Yes
/No
rather than vnow
? The HTML is written by another developer, so I'm not allowed to amend it.
Here's my Java code for Selenium:
public static WebElement chkbx_selectMovieType(WebDriver driver, String value) throws Exception{
try{
List<WebElement> chkbxMovieType = driver.findElements(By.name("movie_Type"));
for(WebElement chkbx : chkbxMovieType){
if(chkbx.getAttribute("value").equalsIgnoreCase(value))
chkbx.click();
}
}catch (Exception e){
throw(e);
}
return element;
}
Any suggestion is welcome. Thanks.