Full CSS selector matching has not been implemented yet.
Depending on your use case, you may be able to match on the type (tag name), and then filter the results using the Element's class attribute.
Here is an example of how to do that:
var el = doc.queryAll('div').where((el) =>
el.attributes.keys.contains('class') &&
el.attributes['class'].split(' ').contains('nav')).first;
Hopefully someone will implement the query selector matching support soon - because this work around is very inefficient for documents with a lot of div tags.
Another solution is to do your own traversal - something like this:
queryClass(Node element, String className) {
for (var node in element.nodes) {
if (node is! Element) continue;
if (node.attributes.keys.contains('class')
&& node.attributes['class'].split(' ').contains(className)) {
return node;
}
var result = queryClass(node, className);
if (result != null) return result;
}
return null;
}
main() {
var doc = parse(...);
var el = queryClass(doc, 'nav');
print(el);
}