Xpath @class= does not work as in chrome.

Open
#47 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
backend

Research direction

Start with the Xsoup.compile(xpath).evaluate(document) entry point shown in the report and compare how the @class predicate is interpreted against the supplied HTML. No source file or test is named; done means determining the intended XPath behavior and adding or updating coverage so the reported class-matching result is consistent with that behavior.

Written by the indexing model from the issue text.

Description

If I run the following code:

`

String html = "<!DOCTYPE html>" +
    "<html>" +
    "  <head>" +
    "    <title>test</title>" +
    "  </head>" +
    "  <body>" +
    "  <div class=\"g\">" +
    "  </div>" +
    "  <div class=\"g x y t\">" +
    "  </div>" +
    "  </body>" +
    "</html>";
Document document = Jsoup.parse(html);

String xpath = "//div[@class='g']";

XElements elements = Xsoup.compile(xpath).evaluate(document);
System.out.println(elements.getElements().size());

for (Element element : elements.getElements())
{
  System.out.println(element.toString());
}

`

I get two elements as out put:

<div class="g">

and

<div class="g x y t">

In Chrome, I get only one, the one with the exact match. Who is wrong, xsoup or Chrome?

Dominant language
Java
Stars
474
Forks
148
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from code4craft/xsoup

All issues in code4craft/xsoup

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.