@Override public ConditionSimpleComponent pseudoClassToXPath(PseudoClassSelector pseudoClassSelector) { String notSelector = pseudoClassSelector.getPseudoClassContent(); String insideHasXPath = XPathComponentCompilerService.compileSelectorList(notSelector).toXPath(); insideHasXPath = insideHasXPath.substring(1, insideHasXPath.length()-1); return new ConditionSimpleComponent("[" + insideHasXPath + "]"); }
@Override public ConditionSimpleComponent pseudoClassToXPath(PseudoClassSelector pseudoClassSelector) { String notSelector = pseudoClassSelector.getPseudoClassContent(); String insideHasXPath = XPathComponentCompilerService.compileSelectorList(notSelector).toXPath(); insideHasXPath = insideHasXPath.substring(1, insideHasXPath.length()-1); return new ConditionSimpleComponent("[" + insideHasXPath + "]"); }
@Test public void attribute_escaping__maybe_should_change() { String selector = "[attr=\"a\\\"bc\"]"; // [attr="a\"bc"] TagComponentList compileSelectorList = XPathComponentCompilerService.compileSelectorList(selector); String xPath = compileSelectorList.toXPath(); assertThat(xPath, is("(.//*[@*[translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'attr'] = 'a\\\"bc'])")); // (.//*[@attr = 'a\"bc']) }
@Test public void toXPath__id() { TagComponentList compileSelectorList = XPathComponentCompilerService.compileSelectorList("#ball"); assertThat(compileSelectorList.toXPath(), is("(.//*[@id = 'ball'])")); }
@Test public void toXPath__and_conditional() { TagComponentList compileSelectorList = XPathComponentCompilerService.compileSelectorList(".a.b"); assertThat(compileSelectorList.toXPath(), is("(.//*[contains(concat(' ', normalize-space(@class), ' '), ' a ') and contains(concat(' ', normalize-space(@class), ' '), ' b ')])")); }