To clarify, the sequence of events is as follows:
- Navigate to the requisite page
- Find the button in page
- Click the button
- Form is submitted
My test code (as pseudo code) is as follows:
final Page page = getPage(); final WebElement button = page.getButton(); button.click(); Assert.assertFalse(button.isEnabled(), "Button still enabled");
The button is actually a div with an attached onClick handler, which looks like this:
-- Before Click <div id="button" onclick="..." class="action-button"> <i class="fa fa-play"></i> Run </div> -- After Click <div id="button" class="action-button" disabled="disabled"> <i class="fa fa-play"></i> Run </div>
The actual submit button itself is hidden for reasons I can't change, so when the user clicks on the div I've documented, the onClick event actually calls the hidden submit button's click event and also sets the div to disabled and removes the onClick handler.
It seems as though the .click() event is blocking until the page reloads, which means by the time the assert is executed the button object is no longer referenced, and I can't check the state.
Is there a way to assert something on the button before the page reloads?