code4craft / xsoup

When jsoup meets XPath.
MIT License
466 stars 151 forks source link

class="class-name-with-a-space " cannot be found using @class="class-name-with-a-space " #39

Closed ShenalSenarath closed 6 years ago

ShenalSenarath commented 6 years ago
Document doc = Jsoup.parse("<span><div class=\"class-name-with-a-space \" >This is a test element</div></span>");
Elements elems = Xsoup.compile("//div[@class=\"class-name-with-a-space \"]").evaluate(doc).getElements();
System.out.println(elems.size());// Output is 0- no elements are extracted.

When the xpath get evaluated it seems that the class name is getting trimmed as follwing code will give a element.

Document doc = Jsoup.parse("<span><div class=\"class-name-with-out-space\" >This is a test element</div></span>");
Elements elems = Xsoup.compile("//div[@class=\"class-name-with-out-space \"]").evaluate(doc).getElements();
System.out.println(elems.size());// Output is 1

Even though the xpath contains a space it ignores and give an element

ShenalSenarath commented 6 years ago

Seems the issue is the Jsoup version

        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.7.3</version>
        </dependency> 

When upgraded to 1.8.3 the issue is not present. Thus closing the issue