@Override public CssCondition visit(AstCssEqualsOrHasAttributeCondition astCssEqualsOrHasAttributeCondition) { return new CssEqualsOrHasAttributeCondition(astCssEqualsOrHasAttributeCondition); }
protected String toXPath() { if (this.getWantedValue() != null) { String escapedWantedValue = SelectorUtils.intoEscapedXPathString(this.getWantedValue()); return AttributeEvaluatorUtils.toXPathAttribute(this.getAttributeName()) + "=" + escapedWantedValue; } return AttributeEvaluatorUtils.toXPathAttribute(this.getAttributeName()); }
protected CssFinder toCSS() { if (this.getWantedValue() != null) { return super.toCSS(); } return new CssFinder("[" + this.getCssEscapedAttributeName() + "]"); }
@Test public void toElementFinder__has_attribute() { // given CssEqualsOrHasAttributeCondition hasAttributeCondition = new CssEqualsOrHasAttributeCondition(new AstCssEqualsOrHasAttributeCondition("attrib")); ElementFinder previous = ElementFinderUtilsTest.UNIVERSAL_SELECTOR_FINDER; // when ElementFinder elementFinder = hasAttributeCondition.toElementFinder(previous); // then assertThat(elementFinder.toCssString(), is("[attrib]")); assertThat(elementFinder.canFetchThroughCssAlone(), is(true)); assertThat(elementFinder.getXPathExpression(), is(".//*[@*[translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'attrib']]")); assertThat(elementFinder.getElementFilterList().getElementFilters(), empty()); }
protected CssFinder toCSS() { if (this.getWantedValue() != null) { return super.toCSS(); } return new CssFinder("[" + this.getCssEscapedAttributeName() + "]"); }
@Test public void toElementFinder__equals_attribute() { // given CssEqualsOrHasAttributeCondition hasAttributeCondition = new CssEqualsOrHasAttributeCondition(new AstCssEqualsOrHasAttributeCondition("attrib", "valz")); ElementFinder previous = ElementFinderUtilsTest.UNIVERSAL_SELECTOR_FINDER; // when ElementFinder elementFinder = hasAttributeCondition.toElementFinder(previous); // then assertThat(elementFinder.toCssString(), is("[attrib='valz']")); assertThat(elementFinder.canFetchThroughCssAlone(), is(true)); assertThat(elementFinder.getXPathExpression(), is(".//*[@*[translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'attrib']='valz']")); assertThat(elementFinder.getElementFilterList().getElementFilters(), empty()); }
protected String toXPath() { if (this.getWantedValue() != null) { String escapedWantedValue = SelectorUtils.intoEscapedXPathString(this.getWantedValue()); return AttributeEvaluatorUtils.toXPathAttribute(this.getAttributeName()) + "=" + escapedWantedValue; } return AttributeEvaluatorUtils.toXPathAttribute(this.getAttributeName()); }
@Override public CssCondition visit(AstCssEqualsOrHasAttributeCondition astCssEqualsOrHasAttributeCondition) { return new CssEqualsOrHasAttributeCondition(astCssEqualsOrHasAttributeCondition); }