Skip to content

XpathElementSpecification cannot match text containing single quotes  #2

@crafds1234

Description

@crafds1234

E.g. this spec fails

anElement().withText("Some text with 'ABC' quoted with single quotes")

with this error:

InvalidSelectorError: Unable to locate an element with the xpath expression //*[text() = 'Some text with 'ABC' quoted with single quotes'] because of the following error:
SyntaxError: The expression is not a legal expression.

On inspection of com.lmax.elementspec.XPathElementSpecification#withText :

appendCondition("text() = '" + text + "'")

The code could detect single/double quotes and use the 'other' quote to quote the string for the test.

The XPath Recommendation (http://www.w3.org/TR/xpath) states:

 Literal ::=   '"' [^"]* '"' 
            | "'" [^']* "'"

So it is impossible to test a single string that contains both types of quotes without complex construction of the test string by concat-ing litertals; e.g.:

*[@text = concat('"', "'")]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions