Reputation: 25
I want mark some checkboxes as checked using Selenium and Java, but in the .css style sheet their "width" and "height" is set to "100", yet in the browser they appear as normal checkboxes. Because of this selenium finds them and succesfully executes .click() function, but the checkbox does not get selected. Is there a way to simply set the checkbox as selected without using .click() ?
Upvotes: 1
Views: 886
Reputation: 473833
Difficult to say without a reproducible sample, but you may try clicking via javascript:
WebElement checkbox = driver.findElement(By.ID("mycheckbox"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", checkbox);
See here the differences:
Upvotes: 1
Reputation: 5758
Im afraid there is no select() method on a check box, but you could write something like this and reuse it.. which will abstract the operation of select
if ( !driver.findElement(By.id("idOfTheElement")).isSelected() )
{
driver.findElement(By.id("idOfTheElement")).click();
}
Upvotes: 1