@Override public CssCondition visit(AstCssEndsWithAttributeCondition astCssEndsWithAttributeCondition) { return new CssEndsWithAttributeCondition(astCssEndsWithAttributeCondition); }
protected String toXPath() { String escapedAttributeName = AttributeEvaluatorUtils.toXPathAttribute(this.getAttributeName()); String attrValue = this.getWantedValue(); String escapedWantedValue = SelectorUtils.intoEscapedXPathString(this.getWantedValue()); return "substring("+escapedAttributeName+", string-length(" + escapedAttributeName + ")-" + (attrValue.length() - 1) + ") = " + escapedWantedValue; }
@Test public void toElementFinder() { // given CssEndsWithAttributeCondition endsWithAttributeCondition = new CssEndsWithAttributeCondition(new AstCssEndsWithAttributeCondition("attribute", "stringToEnd")); ElementFinder previous = ElementFinderUtilsTest.UNIVERSAL_SELECTOR_FINDER; // when ElementFinder elementFinder = endsWithAttributeCondition.toElementFinder(previous); // then assertThat(elementFinder.toCssString(), is("[attribute$='stringToEnd']")); assertThat(elementFinder.canFetchThroughCssAlone(), is(true)); String attrName = "@*[translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'attribute']"; assertThat(elementFinder.getXPathExpression(), is(".//*[substring("+attrName+", string-length("+attrName+")-10) = 'stringToEnd']")); assertThat(elementFinder.getElementFilterList().getElementFilters(), empty()); }
protected String toXPath() { String escapedAttributeName = AttributeEvaluatorUtils.toXPathAttribute(this.getAttributeName()); String attrValue = this.getWantedValue(); String escapedWantedValue = SelectorUtils.intoEscapedXPathString(this.getWantedValue()); return "substring("+escapedAttributeName+", string-length(" + escapedAttributeName + ")-" + (attrValue.length() - 1) + ") = " + escapedWantedValue; }
@Override public CssCondition visit(AstCssEndsWithAttributeCondition astCssEndsWithAttributeCondition) { return new CssEndsWithAttributeCondition(astCssEndsWithAttributeCondition); }