org.openqa.selenium.internal.FindsByXPath Java Examples

The following examples show how to use org.openqa.selenium.internal.FindsByXPath. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdfFinder.java    From adf-selenium with Apache License 2.0 6 votes vote down vote up
@Override
public List<WebElement> findElements(SearchContext searchContext) {
    logger.finer("finding label " + label + " in " + searchContext);
    String safeLabel;
    if (label.contains("'")) {
        // replace each ' with ', "'", ' so we can use it in a concat expression
        // makes concat('O', "'", 'Neil') from O'Neil
        safeLabel = "concat('" + label.replace("'", "', \"'\", '") + "')";
    } else {
        safeLabel = "'" + label + "'";
    }
    // start from . for instances where we are searching within a scoped element
    // tr elements having a _afrrk (rowkey) attribute are considered tree nodes
    String xpath = ".//tr[@_afrrk and .//span[text()=" + safeLabel + "]]";
    logger.finer("using xpath " + xpath);
    return ((FindsByXPath) searchContext).findElementsByXPath(xpath);
}
 
Example #2
Source File: ByExtended.java    From stevia with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public WebElement findElement(SearchContext context) {
	long t0 = System.currentTimeMillis();
	try {
		int indexOf = ownXpathExpression.indexOf("//", 3);
		if (indexOf > -1) { // we found an // inside the selector
			String[] splitSelectors = ownXpathExpression.substring(2).split(Pattern.quote("//"));
			
			WebElement parent = ((FindsByXPath) context).findElementByXPath("//"+splitSelectors[0]);
			for (int i = 1; i < splitSelectors.length; i++) {
				if (parent == null) {
					throw new WebDriverException("Failed to match the parent selector : "+splitSelectors[i-1]);
				}
				WebElement found = parent.findElement(By.xpath(".//"+splitSelectors[i]));
				if (found != null) {
					parent = found;
				} else {
					throw new WebDriverException("Failed to match the selector : "+splitSelectors[i]+" within "+ownXpathExpression);
				}
			}
			
			// by here, we should have the parent WebElement to contain what we want.
			//LOG.info("Found compound selector : "+parent.toString());
			return parent;
		}
		// simple case: one selector
		return ((FindsByXPath) context).findElementByXPath(ownXpathExpression);
	} finally {
		long l = System.currentTimeMillis()-t0;
		if (l > 100) {
			LOG.warn("SLOW findElement() = {}ms. Slow selector : {} ", l,  ownXpathExpression);
		}
	}
}
 
Example #3
Source File: ByExtended.java    From stevia with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public List<WebElement> findElements(SearchContext context) {
	long t0 = System.currentTimeMillis();
	try {
		return ((FindsByXPath) context)
			.findElementsByXPath(ownXpathExpression);
	} finally {
		long l = System.currentTimeMillis()-t0;
		if (l > 100) {
			LOG.warn("SLOW findElements() = {}ms. Slow selector : {} ", l,  ownXpathExpression);
		}
	}
}
 
Example #4
Source File: ByPartialVisibleText.java    From darcy-webdriver with GNU General Public License v3.0 4 votes vote down vote up
@Override
public WebElement findElement(SearchContext context) {
    return ((FindsByXPath) context).findElementByXPath(".//*["
            + textContains(text) + "]");
}
 
Example #5
Source File: ForwardingTargetedWebDriver.java    From darcy-webdriver with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<WebElement> findElementsByXPath(String using) {
    return targetedWebElements(((FindsByXPath) driver()).findElementsByXPath(using));
}
 
Example #6
Source File: ForwardingTargetedWebDriver.java    From darcy-webdriver with GNU General Public License v3.0 4 votes vote down vote up
@Override
public WebElement findElementByXPath(String using) {
    return targetedWebElement(((FindsByXPath) driver()).findElementByXPath(using));
}
 
Example #7
Source File: TargetedWebElement.java    From darcy-webdriver with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<WebElement> findElementsByXPath(String using) {
    return targetedWebElements(((FindsByXPath) element()).findElementsByXPath(using));
}
 
Example #8
Source File: TargetedWebElement.java    From darcy-webdriver with GNU General Public License v3.0 4 votes vote down vote up
@Override
public WebElement findElementByXPath(String using) {
    return targetedWebElement(((FindsByXPath) element()).findElementByXPath(using));
}
 
Example #9
Source File: ByPartialVisibleTextIgnoreCase.java    From darcy-webdriver with GNU General Public License v3.0 4 votes vote down vote up
@Override
public WebElement findElement(SearchContext context) {
    return ((FindsByXPath) context).findElementByXPath(".//*["
            + textContainsIgnoringCase(text) + "]");
}
 
Example #10
Source File: ByPartialVisibleTextIgnoreCase.java    From darcy-webdriver with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<WebElement> findElements(SearchContext context) {
    return ((FindsByXPath) context).findElementsByXPath(".//*["
            + textContainsIgnoringCase(text) + "]");
}
 
Example #11
Source File: RobustElementWrapper.java    From Selenium-Foundation with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({"squid:S3776", "squid:MethodCyclomaticComplexity"})
public RobustElementWrapper(
                final WebElement element, final WrapsContext context, final By locator, final int index) {
    
    // if specified element is already robust
    if (element instanceof RobustWebElement) {
        RobustElementWrapper wrapper = ((InterceptionAccessor) element).getInterceptor();
        this.acquiredAt = wrapper.acquiredAt;
        
        this.wrapped = wrapper.wrapped;
        this.context = wrapper.context;
        this.locator = wrapper.locator;
        this.index = wrapper.index;
    } else {
        Objects.requireNonNull(context, "[context] must be non-null");
        Objects.requireNonNull(locator, "[locator] must be non-null");
        if (index < OPTIONAL) {
            throw new IndexOutOfBoundsException("Specified index is invalid");
        }
        
        this.wrapped = element;
        this.context = context;
        this.locator = locator;
        this.index = index;
    }
    
    driver = WebDriverUtils.getDriver(this.context.getWrappedContext());
    
    findsByCssSelector = (driver instanceof FindsByCssSelector);
    findsByXPath = (driver instanceof FindsByXPath);
    
    if ((this.index == OPTIONAL) || (this.index > 0)) {
        if (findsByXPath && ( ! (this.locator instanceof By.ByCssSelector))) {
            selector = ByType.xpathLocatorFor(this.locator);
            if (this.index > 0) {
                selector += "[" + (this.index + 1) + "]";
            }
            strategy = Strategy.JS_XPATH;
            
            this.locator = By.xpath(this.selector);
        } else if (findsByCssSelector) {
            selector = ByType.cssLocatorFor(this.locator);
            if (selector != null) {
                strategy = Strategy.JS_CSS;
            }
        }
    }
    
    if (this.wrapped == null) {
        if (this.index == OPTIONAL) {
            acquireReference(this);
        } else {
            refreshReference(null);
        }
    } else if (acquiredAt == 0) {
        acquiredAt = System.currentTimeMillis();
    }
}
 
Example #12
Source File: ByPartialVisibleText.java    From darcy-webdriver with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<WebElement> findElements(SearchContext context) {
    return ((FindsByXPath) context).findElementsByXPath(".//*["
            + textContains(text) + "]");
}
 
Example #13
Source File: ByAttribute.java    From darcy-webdriver with GNU General Public License v3.0 4 votes vote down vote up
@Override
public WebElement findElement(SearchContext context) {
  return ((FindsByXPath) context).findElementByXPath(".//*["
      + attributeEquals(attribute, word) + "]");
}
 
Example #14
Source File: ByAttribute.java    From darcy-webdriver with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<WebElement> findElements(SearchContext context) {
  return ((FindsByXPath) context).findElementsByXPath(".//*["
      + attributeEquals(attribute, word) + "]");
}
 
Example #15
Source File: ByPartialAttribute.java    From darcy-webdriver with GNU General Public License v3.0 4 votes vote down vote up
@Override
public WebElement findElement(SearchContext context) {
  return ((FindsByXPath) context).findElementByXPath(".//*["
      + attributeContains(attribute, word) + "]");
}
 
Example #16
Source File: ByPartialAttribute.java    From darcy-webdriver with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<WebElement> findElements(SearchContext context) {
  return ((FindsByXPath) context).findElementsByXPath(".//*["
      + attributeContains(attribute, word) + "]");
}
 
Example #17
Source File: WebDriverWrapper.java    From bobcat with Apache License 2.0 4 votes vote down vote up
/**
 * Finds elements by xpath.
 */
@Override
public List<WebElement> findElementsByXPath(String xPath) {
  return ((FindsByXPath) super.getWrappedDriver()).findElementsByXPath(xPath);
}
 
Example #18
Source File: WebDriverWrapper.java    From bobcat with Apache License 2.0 4 votes vote down vote up
/**
 * Finds element by xpath.
 */
@Override
public WebElement findElementByXPath(String xPath) {
  return ((FindsByXPath) super.getWrappedDriver()).findElementByXPath(xPath);
}