I’m adding web tests to my project using Selenium. I already have a bunch of tests that check for a specific element using:
final WebElement dateElement = web.findElement(By.id(elementId));
And this works fine.
Now I have another requirement. This is in my generated page:
<input type="text" id="dateElement" name="dateElement" value="bunch of monkeys" tabindex="101" placeholder="yyyy-mm-dd">
<span class="error">dateElement is an invalid date</span>
How can I get hold of the error message?
I’d like something that allows me to request the span element with class “error” that is just after dateElement.
(This error message was ganerated by Spring MVC, so it’s not easy to change it directly. Possible I guess, but I’d prefer not).
Any alternative idea is welcome.
OK, I already found a solution using Xpath and following-sibling, it wasn’t too complicated.
This gives me what I wanted, and throws a
NoSuchElementExceptionwhen it’s not here, which is exactly what I want.