@Override public ConditionSimpleComponent pseudoClassToXPath(PseudoClassSelector pseudoClassSelector) { return new ConditionSimpleComponent("[(" + "( local-name() = 'input' and @type = 'submit' ) or " + "( local-name() = 'button' and (@type = 'submit' or not(@type)) )" + ")]"); }
@Override public ConditionSimpleComponent pseudoClassToXPath(PseudoClassSelector pseudoClassSelector) { return new ConditionSimpleComponent("[(" + "( local-name() = 'input' and @type = 'submit' ) or " + "( local-name() = 'button' and (@type = 'submit' or not(@type)) )" + ")]"); }
public static ConditionSimpleComponent nthChild(int a, int b) { // a == 0: 0n+b 0n-b if (a == 0) { return new ConditionSimpleComponent("[position() = " + b + "]"); } // a < 0: -an+b -an-b if (a < 0) { return new ConditionSimpleComponent("[(position() - " + b + ") mod " + a + " = 0 and position() <= " + b + "]"); } // a > 0: an+b an-b return new ConditionSimpleComponent("[(position() - " + b + ") mod " + a + " = 0 and position() >= " + b + "]"); }
@Override public ConditionSimpleComponent toXPath(ArgumentMap argumentMap, T selector) { // if it is unknown, we can't convert it, so we simply ignore it LOGGER.warn("CSS Selector '"+selector+"' is unknown. Ignoring it."); return new ConditionSimpleComponent(); }
@Override public ConditionSimpleComponent conditionToXPath(ArgumentMap argumentMap, Selector simpleSelector, T condition) { // if it is unknown, we can't convert it, so we simply ignore it LOGGER.warn("CSS Selector Condition '"+condition+"' is unknown. Ignoring it."); return new ConditionSimpleComponent(ElementFilter.FILTER_NOTHING); }
@Override public ConditionSimpleComponent pseudoClassToXPath(PseudoClassSelector pseudoClassSelector) { pseudoClassNotSupportedWhenUsedDirectly(HIDDEN_PSEUDO_CLASS_NO_COLON); // we can't use XPath because it can't see the styles affecting the element's classes, which can pretty much // turn any element, including <html> itself or <head>, visible. return new ConditionSimpleComponent(HIDDEN_FILTER); }
@Override public ConditionSimpleComponent pseudoClassToXPath(PseudoClassSelector pseudoClassSelector) { pseudoClassNotSupportedWhenUsedDirectly(CHECKED_PSEUDO_CLASS_NO_COLON); // NOTE: This XPath does not work. Sometimes an element is checked WITHOUT having a checked attribute return new ConditionSimpleComponent("[" + "(" + "(self::input and (@type = 'radio' or @type = 'checkbox') and @checked) " + "or " + "(" + SELECTED_PSEUDO_CONDITION + ")" + ")" + "]"); }
@Override public ConditionSimpleComponent pseudoClassToXPath(PseudoClassSelector pseudoClassSelector) { pseudoClassNotSupportedWhenUsedDirectly(CHECKED_PSEUDO_CLASS_NO_COLON); // NOTE: This XPath does not work. Sometimes an element is checked WITHOUT having a checked attribute return new ConditionSimpleComponent("[" + "(" + "(self::input and (@type = 'radio' or @type = 'checkbox') and @checked) " + "or " + "(" + SELECTED_PSEUDO_CONDITION + ")" + ")" + "]"); }
@Override public ConditionSimpleComponent pseudoClassToXPath(PseudoClassSelector pseudoClassSelector) { pseudoClassNotSupportedWhenUsedDirectly(FOCUSABLE_PSEUDO_CLASS_NO_COLON); // after filtering with XPath, we still have to check visibility (filter)... return new ConditionSimpleComponent("[" + FOCUSABLE_XPATH + "]", focusablePseudoClassFilter); }
@Override public ConditionSimpleComponent pseudoClassToXPath(PseudoClassSelector pseudoClassSelector) { pseudoClassNotSupportedWhenUsedDirectly(VISIBLE_PSEUDO_CLASS_NO_COLON); // we can't use XPath because it can't see the styles affecting the element's classes, which can pretty much // turn any element, including <html> itself or <head>, visible. return new ConditionSimpleComponent(VISIBLE_FILTER); }
@Override public ConditionSimpleComponent conditionToXPath(ArgumentMap argumentMap, Selector simpleSelector, AttributeCondition attributeCondition) { String wantedClassName = attributeCondition.getValue(); String backslashEscapedClassName = wantedClassName.replaceAll("\\\\\"", "\""); String xPathEscapedClassName = intoEscapedXPathString(" "+backslashEscapedClassName+" "); return new ConditionSimpleComponent("[contains(concat(' ', normalize-space(@class), ' '), " + xPathEscapedClassName + ")]"); }
@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 conditionToXPath(ArgumentMap argumentMap, Selector simpleSelector, AttributeCondition attributeCondition) { String attributeName = AttributeEvaluatorUtils.getXPathAttribute(attributeCondition); String wantedValue = SelectorUtils.intoEscapedXPathString(attributeCondition.getValue()); return new ConditionSimpleComponent("[contains(" + attributeName + ", " + wantedValue + ")]"); }
@Override public ConditionSimpleComponent conditionToXPath(ArgumentMap argumentMap, Selector simpleSelector, AttributeCondition attributeCondition) { String attributeName = AttributeEvaluatorUtils.getXPathAttribute(attributeCondition); String wantedValue = SelectorUtils.intoEscapedXPathString(attributeCondition.getValue()); return new ConditionSimpleComponent("[starts-with(" + attributeName + ", " + wantedValue + ")]"); }
@Override public ConditionSimpleComponent pseudoClassToXPath(PseudoClassSelector pseudoClassSelector) { String textToContain = pseudoClassSelector.getPseudoClassContent(); textToContain = SelectorUtils.unescapeString(textToContain); String wantedTextToContain = SelectorUtils.intoEscapedXPathString(textToContain); return new ConditionSimpleComponent("[contains(string(.), " + wantedTextToContain + ")]"); }
@Override public ConditionSimpleComponent conditionToXPath(ArgumentMap argumentMap, Selector simpleSelector, AttributeCondition attributeCondition) { String attributeName = AttributeEvaluatorUtils.getXPathAttribute(attributeCondition); String wantedValueSurroundedBySpaces = SelectorUtils.intoEscapedXPathString(" " + attributeCondition.getValue() + " "); return new ConditionSimpleComponent("[contains(concat(' ', normalize-space(" + attributeName + "), ' '), " + wantedValueSurroundedBySpaces + ")]"); }
@Override public ConditionSimpleComponent conditionToXPath(ArgumentMap argumentMap, Selector simpleSelector, AttributeCondition attributeCondition) { String attributeName = AttributeEvaluatorUtils.getXPathAttribute(attributeCondition); String wantedValue = SelectorUtils.intoEscapedXPathString(attributeCondition.getValue()); return new ConditionSimpleComponent("[starts-with(" + attributeName + ", " + wantedValue + ")]"); }
@Override public ConditionSimpleComponent conditionToXPath(ArgumentMap argumentMap, Selector simpleSelector, AttributeCondition attributeCondition) { String attributeName = AttributeEvaluatorUtils.getXPathAttribute(attributeCondition); String wantedValueSurroundedBySpaces = SelectorUtils.intoEscapedXPathString(" " + attributeCondition.getValue() + " "); return new ConditionSimpleComponent("[contains(concat(' ', normalize-space(" + attributeName + "), ' '), " + wantedValueSurroundedBySpaces + ")]"); }
@Override public ConditionSimpleComponent conditionToXPath(ArgumentMap argumentMap, Selector simpleSelector, AttributeCondition attributeCondition) { String attributeName = AttributeEvaluatorUtils.getXPathAttribute(attributeCondition); String wantedValue = SelectorUtils.intoEscapedXPathString(attributeCondition.getValue()); String wantedValueWithSuffix = SelectorUtils.intoEscapedXPathString(attributeCondition.getValue() + "-"); return new ConditionSimpleComponent("[(" + attributeName + " = " + wantedValue + " or starts-with(" + attributeName + ", " + wantedValueWithSuffix + "))]"); }
@Override public TagComponent toXPath(ArgumentMap argumentMap, SiblingSelector siblingSelector) { TagComponent previousCompiledExpression = XPathComponentCompilerService.compileSelector(argumentMap, siblingSelector.getSelector()); TagComponent siblingSelectorCompiledAdjacentExpression = XPathComponentCompilerService.compileSelector(argumentMap, siblingSelector.getSiblingSelector()); ConditionSimpleComponent positionOne = new ConditionSimpleComponent("[position() = 1]"); TagComponent siblingAtPositionOne = siblingSelectorCompiledAdjacentExpression.cloneAndCombineTo(positionOne); return AdjacentComponent.combine(previousCompiledExpression, siblingAtPositionOne); }