String simpleSelector = valueOf(s.getSimpleSelector()); return valueOf(s.getCondition()); } else { return simpleSelector + valueOf(s.getCondition());
private boolean isPseudoElementRule( final ElementStyleRule rule ) { final List<CSSSelector> selectorList = rule.getSelectorList(); for ( int i = 0; i < selectorList.size(); i += 1 ) { final CSSSelector selector = selectorList.get( i ); if ( selector == null ) { continue; } if ( selector.getSelectorType() != Selector.SAC_CONDITIONAL_SELECTOR ) { continue; } final ConditionalSelector cs = (ConditionalSelector) selector; final Condition condition = cs.getCondition(); if ( condition.getConditionType() != Condition.SAC_PSEUDO_CLASS_CONDITION ) { continue; } return true; } return false; }
private boolean isPseudoElementRule( final CSSStyleRule rule ) { final CSSSelector selector = rule.getSelector(); if ( selector == null ) { return false; } if ( selector.getSelectorType() != Selector.SAC_CONDITIONAL_SELECTOR ) { return false; } final ConditionalSelector cs = (ConditionalSelector) selector; final Condition condition = cs.getCondition(); if ( condition.getConditionType() != Condition.SAC_PSEUDO_CLASS_CONDITION ) { return false; } return true; }
@Override public boolean is(WebDriver driver, WebElement element, ArgumentMap argumentMap, ConditionalSelector conditionalSelector) { Condition condition = conditionalSelector.getCondition(); SimpleSelector simpleSelector = conditionalSelector.getSimpleSelector(); return CssSelectorMatcherService.elementMatchesSelector(driver, element, argumentMap, simpleSelector) && isCondition(driver, element, argumentMap, simpleSelector, condition); }
private void applyConditionalPseudoStyle(ExtendedCSSRule parentRule, String pseudoInstance, Object element, CSSStyleDeclaration styleWithPseudoInstance) { SelectorList selectorList = parentRule.getSelectorList(); for (int j = 0; j < selectorList.getLength(); j++) { Selector item = selectorList.item(j); // search for conditional selectors if (item instanceof ConditionalSelector) { Condition condition = ((ConditionalSelector) item).getCondition(); // we're only interested in attribute selector conditions if (condition instanceof AttributeCondition) { String value = ((AttributeCondition) condition).getValue(); if (value.equals(pseudoInstance)) { // if we match the pseudo, apply the style applyStyleDeclaration(element, styleWithPseudoInstance, pseudoInstance); return; } } } } }
@Override public boolean is(WebDriver driver, WebElement element, ArgumentMap argumentMap, ConditionalSelector conditionalSelector) { Condition condition = conditionalSelector.getCondition(); SimpleSelector simpleSelector = conditionalSelector.getSimpleSelector(); return CssSelectorMatcherService.elementMatchesSelector(driver, element, argumentMap, simpleSelector) && isCondition(driver, element, argumentMap, simpleSelector, condition); }
public static Selector createSelectorAndreplaceSelectorVariableWithValue( Selector selector, String variable, String value) throws Exception { SelectorFactoryImpl factory = new SelectorFactoryImpl(); ElementSelector es = factory.createElementSelector( null, ((ElementSelector) selector).getLocalName().replaceAll( variable, value)); if (selector instanceof ConditionalSelector) { return factory.createConditionalSelector(es, ((ConditionalSelector) selector).getCondition()); } else if (selector instanceof DescendantSelector) { return factory.createDescendantSelector(es, ((DescendantSelector) selector).getSimpleSelector()); } else if (selector instanceof ChildSelectorImpl) { return factory.createChildSelector(es, ((DescendantSelector) selector).getSimpleSelector()); } else { throw new Exception("Invalid selector type"); } } }
public CssConditionalSelector translate(ArgumentMap argumentMap, ConditionalSelector conditionalSelector) { Condition condition = conditionalSelector.getCondition(); SimpleSelector simpleSelector = conditionalSelector.getSimpleSelector(); CssSelector cssSelector = cssSelectorTranslator.translate(argumentMap, simpleSelector); CssCondition cssCondition = cssConditionTranslator.translate(simpleSelector, argumentMap, condition); return new CssConditionalSelector(cssSelector, cssCondition); }
.getCondition().getConditionType(); if (selectorConditionType == conditionType) {
@Override public TagComponent toXPath(ArgumentMap argumentMap, ConditionalSelector conditionalSelector) { Condition condition = conditionalSelector.getCondition(); SimpleSelector simpleSelector = conditionalSelector.getSimpleSelector(); TagComponent tagComponent = XPathComponentCompilerService.compileSelector(argumentMap, simpleSelector); ConditionComponent compiledCondition = conditionToXPath(argumentMap, simpleSelector, condition); return tagComponent.cloneAndCombineTo(compiledCondition); }
public CssConditionalSelector translate(ArgumentMap argumentMap, ConditionalSelector conditionalSelector) { Condition condition = conditionalSelector.getCondition(); SimpleSelector simpleSelector = conditionalSelector.getSimpleSelector(); CssSelector cssSelector = cssSelectorTranslator.translate(argumentMap, simpleSelector); CssCondition cssCondition = cssConditionTranslator.translate(simpleSelector, argumentMap, condition); return new CssConditionalSelector(cssSelector, cssCondition); }
@Override public TagComponent toXPath(ArgumentMap argumentMap, ConditionalSelector conditionalSelector) { Condition condition = conditionalSelector.getCondition(); SimpleSelector simpleSelector = conditionalSelector.getSimpleSelector(); TagComponent tagComponent = XPathComponentCompilerService.compileSelector(argumentMap, simpleSelector); ConditionComponent compiledCondition = conditionToXPath(argumentMap, simpleSelector, condition); return tagComponent.cloneAndCombineTo(compiledCondition); }
private static ConditionalSelector createConditionSelectorWithSomePartReplaced( ConditionalSelector oldConditionSelector, String toBeReplacedSelectorName, SimpleSelector candidateSelector) { if (oldConditionSelector == null || !toString(oldConditionSelector).contains( toBeReplacedSelectorName)) { return oldConditionSelector; } SelectorFactory selectorFactory = new SelectorFactoryImpl(); if (candidateSelector instanceof ElementSelector) { return selectorFactory.createConditionalSelector(candidateSelector, oldConditionSelector.getCondition()); } if (candidateSelector instanceof ConditionalSelector) { // TODO some cases not covered. ConditionalSelector candidateConditionSelector = (ConditionalSelector) candidateSelector; Condition newCondition = createConditionWithSomePartReplaced( oldConditionSelector.getCondition(), toBeReplacedSelectorName, candidateConditionSelector.getCondition()); return selectorFactory.createConditionalSelector( oldConditionSelector.getSimpleSelector(), newCondition); } return oldConditionSelector; }
public boolean isMatchingPseudoElement( final LayoutElement element, final String pseudo ) { for ( int i = 0; i < activePseudoStyleRules.length; i++ ) { final CSSStyleRule activeStyleRule = activePseudoStyleRules[ i ]; final CSSSelector selector = activeStyleRule.getSelector(); final ConditionalSelector cs = (ConditionalSelector) selector; final Condition condition = cs.getCondition(); final AttributeCondition ac = (AttributeCondition) condition; if ( ObjectUtilities.equal( ac.getValue(), pseudo ) == false ) { continue; } final SimpleSelector simpleSelector = cs.getSimpleSelector(); if ( isMatch( element, simpleSelector ) ) { return true; } } return false; }
public boolean isMatchingPseudoElement( final ReportElement element, final String pseudo ) { for ( int i = 0; i < activePseudoStyleRules.length; i++ ) { final ElementStyleRule activeStyleRule = activePseudoStyleRules[i]; final List<CSSSelector> selectorList = activeStyleRule.getSelectorList(); for ( int x = 0; x < selectorList.size(); x += 1 ) { final CSSSelector selector = selectorList.get( x ); if ( selector instanceof ConditionalSelector == false ) { continue; } final ConditionalSelector cs = (ConditionalSelector) selector; final Condition condition = cs.getCondition(); final AttributeCondition ac = (AttributeCondition) condition; if ( ObjectUtilities.equal( ac.getValue(), pseudo ) == false ) { continue; } final SimpleSelector simpleSelector = cs.getSimpleSelector(); if ( isMatch( element, simpleSelector ) ) { return true; } } } return false; }
ConditionalSelector conditionalSelector = (ConditionalSelector) selector; String simpleSelectorString = toString(conditionalSelector .getSimpleSelector()); if (simpleSelectorString != null) { stringBuilder.append(simpleSelectorString); .getCondition()); stringBuilder.append(conditionString); return stringBuilder.toString();
String simpleSelector = valueOf(s.getSimpleSelector()); return valueOf(s.getCondition()); } else { return simpleSelector + valueOf(s.getCondition());
String simpleSelector = valueOf(s.getSimpleSelector()); return valueOf(s.getCondition()); } else { return simpleSelector + valueOf(s.getCondition());
.getSimpleSelector()) & isValidCondition(selectorName, condSelector .getCondition()); case Selector.SAC_DIRECT_ADJACENT_SELECTOR:
@Test public void testConditionToXPath() { W3cCssSelectorListWithMap w3cCssSelectorListWithMap = W3cCssSelectorWithMapParser.parseSelector("span.a.b"); SelectorList selectorList = w3cCssSelectorListWithMap.getSelectorList(); ConditionalSelector selector = (ConditionalSelector) selectorList.item(0); ArgumentMap argumentMap = w3cCssSelectorListWithMap.getArgumentMap(); SimpleSelector simpleSelector = selector.getSimpleSelector(); TagComponent spanTagComponent = XPathComponentCompilerService.compileSelector(argumentMap, simpleSelector); CombinatorCondition combinatorCondition = (CombinatorCondition) selector.getCondition(); ConditionComponent compiledCondition = andConditionalCssSelector.conditionToXPath(argumentMap, simpleSelector, combinatorCondition); TagComponent cs = spanTagComponent.cloneAndCombineTo(compiledCondition); assertThat(cs.toXPath(), is("(.//*[self::span and contains(concat(' ', normalize-space(@class), ' '), ' a ') and contains(concat(' ', normalize-space(@class), ' '), ' b ')])")); assertThat(cs.toXPathCondition(), is("local-name() = 'span' and contains(concat(' ', normalize-space(@class), ' '), ' a ') and contains(concat(' ', normalize-space(@class), ' '), ' b ')")); }