Your solution for case 1 seems like it should work.
For case 2, you'll probably need to invoke JavaScript on the page from within Selenium to check if the element has any event handlers assigned, I believe the following should do the trick:
new WebDriverWait(driver, TIMEOUT).until(new Predicate<WebDriver>() {
public boolean apply(WebDriver driver) {
return (JavascriptExectutor) driver.executeScript(
"arguments[0].onclick == null;", getElement());
}
});
This should get JS to query the current onClick
event handler assigned to the element passed into the JavascriptExecutor
from the method getElement()
and return true if no handler is assigned.
Not actually tested this beyond a quick fiddle with the JS, but it should be all good.
Update: In newer selenium versions, you should be able to use:
ExpectedConditions.not(ExpectedConditions.elementToBeClickable(By))