About "unexpected '#' after 'DESCENDANT_SELECTOR' (Nokogiri::CSS::SyntaxError)"

The error unexpected 'x' after 'DESCENDANT_SELECTOR' (Nokogiri::CSS::SyntaxError) (where x may be basically any character) occurs when the Nokogiri parser receives an invalid selector like .field_with_errors # or td <strong>.

In Cucumber, the culprit will be an invalid step definition that builds an invalid selector:

# inside some step definition:
field = find_field(label)
page.send(expectation, have_css(".field_with_errors ##{field[:id]}"))

The above raises the mentioned error if field[:id] is nil, i.e. the found field has no id.

Fix

Ensure your step definition cannot generate invalid selectors and instead prints better error messages. Adding field.should be_present might help,

Note

This error may be caused when your selenium browser window is too narrow, so that your driver can't see the field. May sound funny but true.

Dominik Schöler about 8 years ago
This website uses short-lived cookies to improve usability.
Accept or learn more