verify if checkbox is checked or if select box has selected specific option

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

verify if checkbox is checked or if select box has selected specific option

zlos7ar
Hi,

is there a way to check :

1. if a checkbox is checked or not ?
2. if dropdown select box has specific option selected ?
Reply | Threaded
Open this post in threaded view
|

Re: verify if checkbox is checked or if select box has selected specific option

softwaretestingforum
Administrator
try these -

public boolean isSelected(By locator) {
    return driver.findElement(locator).isSelected();
}

public boolean isOptionSelected(By locator, String expectedSelection) {
   return new Select(driver.findElement(locator)).getFirstSelectedOption().getText().equals(expectedSelection);
}

 
~ seleniumtests.com