Reputation: 108
Attempting to create a CSS selector or XPATH selector which will find the next span element (not necessarily immediately) after a given element ID.
I was able to select the next span immediately after an element by using the CSS '+', however if the span is not immediately after, this will not work.
#email + span[class*='jsonform-errortext']
This would work if the span was directly after the input element, however it will not work in the example below.
<div>
<input type="text" class="c-form-text-input user-success" name="email" id="email" maxlength="100" required="required">
</div>
<span class="help-block jsonform-errortext" style="display:none;"></span>
Upvotes: 1
Views: 2027
Reputation: 52665
You can try below XPath to get next span even if it's not a sibling:
'//*[@id="email"]/following::span[contains(@class, "jsonform-errortext")]'
Upvotes: 5