I’ve been writing automated regression tests at work over the past month, using Jest and Selenium WebDriver, and have really been struggling to get my tests to pass consistently. I began to suspect that methods like
I ran across this Stack Overflow answer which says,
There does not seem to be a condition equivalent to Python’s
selenium.webdriver.support.expected_conditions.element_to_be_clickable. However, looking at the source for that condition, I see that it does two checks:
- That the element is visible.
- That it is enabled.
So you could wait for both conditions to become true.
This was very exciting indeed. I refactored my helper functions simply by slapping
.isEnabled() on the end of lines like
driver.wait(until.elementLocated(By.css('#overview-link')), config.timeout), ran a test suite 100 times using the zsh command
repeat, and voila! Every. Single. Test. Passed!
I highly recommend using
.isEnabled() instead of just relying on
wait(until.elementLocated.... And add
.isVisible() as needed. I found it wasn’t consistently helpful for me by itself but in combination with
.isEnabled() it should be quite consistent.