org.openqa.selenium.By#toString ( )源码实例Demo

下面列出了org.openqa.selenium.By#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: aquality-selenium-java   文件: ElementFactory.java
/**
 * Extracts XPath from passed locator.
 *
 * @param locator locator to get xpath from.
 * @return extracted XPath.
 */
@Override
protected String extractXPathFromLocator(By locator) {
    String locatorString = locator.toString();
    int indexOfDots = locatorString.indexOf(':');
    String locValuableString = indexOfDots == -1
            // case ByIdOrName:
            ? locatorString.substring(locatorString.indexOf('"')).replace("\"", "")
            : locatorString.substring(indexOfDots + 1).trim();
    Class<? extends By> locatorClass = locator.getClass();
    return getLocatorToXPathTemplateMap().containsKey(locator.getClass())
            ? String.format(getLocatorToXPathTemplateMap().get(locatorClass), locValuableString)
            : super.extractXPathFromLocator(locator);
}
 
源代码2 项目: healenium-web   文件: BaseHandler.java
protected WebElement findElement(By by) {
    try {
        PageAwareBy pageBy = awareBy(by);
        By inner = pageBy.getBy();
        if (engine.isHealingEnabled()) {
            return lookUp(pageBy);
        }
        return driver.findElement(inner);
    } catch (Exception ex) {
        throw new NoSuchElementException("Failed to find element using " + by.toString(), ex);
    }
}
 
源代码3 项目: healenium-web   文件: WebElementProxyHandler.java
@Override
protected WebElement findElement(By by) {
    try {
        PageAwareBy pageBy = awareBy(by);
        if (engine.isHealingEnabled()) {
            return lookUp(pageBy);
        }
        return delegate.findElement(pageBy.getBy());
    } catch (Exception ex) {
        throw new NoSuchElementException("Failed to find element using " + by.toString(), ex);
    }

}
 
源代码4 项目: webtau   文件: FakeWebDriver.java
@Override
public List<WebElement> findElements(By by) {
    if (by instanceof By.ByCssSelector) {
        String rendered = by.toString();
        int idxOfColon = rendered.indexOf(":");
        String css = rendered.substring(idxOfColon + 1).trim();
        return fakesByCss.containsKey(css) ? Collections.singletonList(fakesByCss.get(css)) : Collections.emptyList();
    }

    return Collections.emptyList();
}
 
源代码5 项目: phoenix.webui.framework   文件: AbstractLocator.java
@Override
public String toString()
{
	By by = getBy();
	String srtBy = (by == null ? "null locator" : by.toString());
	
	return srtBy;
}
 
源代码6 项目: masquerade   文件: LoggingInvocationHandler.java
private String formatBy(By by) {
    if (by instanceof Selectors.ByChain) {
        return formatBy(((Selectors.ByChain) by).getLastBy());
    }
    if (by instanceof Selectors.ByCubaId) {
        return ((Selectors.ByCubaId) by).getCubaId();
    }
    return by.toString();
}
 
源代码7 项目: functional-tests-core   文件: Wait.java
public boolean waitForNotVisible(By locator, int timeOut, boolean failOnVisible) {
    this.client.setWait(1);
    long startTime = new Date().getTime();
    boolean found = true;
    for (int i = 0; i < 1000; i++) {
        long currentTime = new Date().getTime();
        if ((currentTime - startTime) < timeOut * 1000) {
            List<UIElement> elements = null;
            try {
                elements = this.find.elementsByLocator(locator);
            } catch (Exception e) {
            }

            if ((elements != null) && (elements.size() != 0)) {
                LOGGER_BASE.debug("OldElement exists: " + locator.toString());
            } else {
                found = false;
                break;
            }
        }
    }
    this.client.setWait(this.settings.defaultTimeout);
    if (found) {
        String error = "OldElement still visible: " + locator.toString();
        LOGGER_BASE.error(error);
        if (failOnVisible) {
            Assert.fail(error);
        }
    } else {
        LOGGER_BASE.debug("OldElement not found: " + locator.toString());
    }
    return found;
}
 
源代码8 项目: rice   文件: WebDriverAftBase.java
protected List<WebElement> findElements(By by, WebElement element) {
    if (element == null) {
        checkForIncidentReport();
        throw new AssertionError("element to findElements on for " + by.toString() + " is null in class " + this.getClass().toString());
    }
    List<WebElement> found = element.findElements(by);
    return found;
}
 
源代码9 项目: carina   文件: LocalizedAnnotations.java
@Override
 public By buildBy() {

     By by = super.buildBy();
     String param = by.toString();
     
     // replace by using localization pattern
     Matcher matcher = L10N_PATTERN.matcher(param);
     while (matcher.find()) {
         int start = param.indexOf(SpecialKeywords.L10N + ":") + 5;
         int end = param.indexOf("}");
         String key = param.substring(start, end);
param = StringUtils.replace(param, matcher.group(), L10N.getText(key));
     }

     if (getField().isAnnotationPresent(Predicate.class)) {
         // TODO: analyze howto determine iOS or Android predicate
         param = StringUtils.remove(param, "By.xpath: ");
         by = MobileBy.iOSNsPredicateString(param);
         // by = MobileBy.AndroidUIAutomator(param);
     } else if (getField().isAnnotationPresent(ClassChain.class)) {
         param = StringUtils.remove(param, "By.xpath: ");
         by = MobileBy.iOSClassChain(param);
     } else if (getField().isAnnotationPresent(AccessibilityId.class)) {
         param = StringUtils.remove(param, "By.name: ");
         by = MobileBy.AccessibilityId(param);
     } else if (getField().isAnnotationPresent(ExtendedFindBy.class)) {
         if (param.startsWith("By.AndroidUIAutomator: ")) {
             param = StringUtils.remove(param, "By.AndroidUIAutomator: ");
             by = MobileBy.AndroidUIAutomator(param);
         }
         LOGGER.debug("Annotation ExtendedFindBy has been detected. Returning locator : " + by);
     } else {
         by = createBy(param);
     }
     return by;
 }
 
源代码10 项目: carina   文件: ExtendedWebElement.java
/**
  * Find Extended Web Element on page using By starting search from this
  * object.
  *
  * @param by Selenium By locator
  * @param name Element name
  * @param timeout Timeout to find
  * @return ExtendedWebElement if exists otherwise null.
  */
 public ExtendedWebElement findExtendedWebElement(final By by, String name, long timeout) {
     if (isPresent(by, timeout)) {
try {
	return new ExtendedWebElement(getCachedElement().findElement(by), name, by);
} catch (StaleElementReferenceException e) {
	return new ExtendedWebElement(getElement().findElement(by), name, by);
}
     } else {
     	throw new NoSuchElementException("Unable to find dynamic element using By: " + by.toString());
     }
 }
 
源代码11 项目: webtau   文件: NullWebElement.java
@Override
public WebElement findElement(By by) {
    return new NullWebElement(by.toString());
}
 
源代码12 项目: WebAndAppUITesting   文件: BaseElement.java
public BaseElement(By by) {
	this.by = by;
	oriElementStr = by.toString();
}
 
源代码13 项目: blueocean-plugin   文件: SmartWebElement.java
public SmartWebElement(WebDriver driver, By by) {
    this(driver, by.toString(), by);
}
 
源代码14 项目: xframium-java   文件: DeviceWebDriver.java
public List<WebElement> findElements( By by )
{
    setLastAction();
    if ( log.isInfoEnabled() )
        log.info( Thread.currentThread().getName() + ": Locating element using [" + by + "]" );
    
    
    if ( cachingEnabled && cachedDocument == null )
        cacheData();

    if ( cachingEnabled && cachedDocument != null )
    {
        try
        {
            XPath xPath = xPathFactory.newXPath();
            String path = by.toString();
            path = path.substring( path.indexOf( ": " ) + 2 );
            NodeList nodes = (NodeList) xPath.evaluate( path, cachedDocument, XPathConstants.NODESET );

            List<WebElement> elementList = new ArrayList<WebElement>( 10 );

            for ( int i = 0; i < nodes.getLength(); i++ )
            {
                if ( reportingElement )
                    elementList.add( new ReportingWebElementAdapter( new CachedWebElement( this, webDriver, by, nodes.item( i ) ), this, by ) );
                else
                    elementList.add( new CachedWebElement( this, webDriver, by, nodes.item( i ) ) );
            }

            return elementList;
        }
        catch ( Exception e )
        {
            log.warn( "Error reading from cache " + e.getMessage() );
            if ( !syntheticConnection )
            {
                cachingEnabled = false;
                cachedDocument = null;
            }
            else
                return null;
        }
    }

    if ( reportingElement )
    {
        List<WebElement> currentList = webDriver.findElements( by );
        if ( !currentList.isEmpty() )
        {
            List<WebElement> newList = new ArrayList<WebElement>( currentList.size() );
            for ( WebElement wE : currentList )
                newList.add( new ReportingWebElementAdapter( wE, this, by ) );
            return newList;
        }
        else
            return currentList;
        
    }
    else
        return webDriver.findElements( by );
}
 
源代码15 项目: carina   文件: ExtendedWebElement.java
public By generateByForList(By by, int index) {
    String locator = by.toString();
    By resBy = null;

    if (locator.startsWith("By.id: ")) {
        resBy = By.id(StringUtils.remove(locator, "By.id: ") + "[" + index + "]");
    }

    if (locator.startsWith("By.name: ")) {
    	resBy = By.name(StringUtils.remove(locator, "By.name: ") + "[" + index + "]");
    }

    if (locator.startsWith("By.xpath: ")) {
    	resBy = By.xpath(StringUtils.remove(locator, "By.xpath: ") + "[" + index + "]");
    }
    if (locator.startsWith("linkText: ")) {
    	resBy = By.linkText(StringUtils.remove(locator, "linkText: ") + "[" + index + "]");
    }

    if (locator.startsWith("partialLinkText: ")) {
    	resBy = By.partialLinkText(StringUtils.remove(locator, "partialLinkText: ") + "[" + index + "]");
    }

    if (locator.startsWith("css: ")) {
    	resBy = By.cssSelector(StringUtils.remove(locator, "css: ") + ":nth-child(" + index + ")");
    }
    
    if (locator.startsWith("By.cssSelector: ")) {
    	resBy = By.cssSelector(StringUtils.remove(locator, "By.cssSelector: ") + ":nth-child(" + index + ")");
    }

    if (locator.startsWith("tagName: ")) {
    	resBy = By.tagName(StringUtils.remove(locator, "tagName: ") + "[" + index + "]");
    }

    /*
     * All ClassChain locators start from **. e.g FindBy(xpath = "**'/XCUIElementTypeStaticText[`name CONTAINS[cd] '%s'`]")
     */
    if (locator.startsWith("By.IosClassChain: **")) {
    	resBy = MobileBy.iOSClassChain(StringUtils.remove(locator, "By.IosClassChain: ") + "[" + index + "]");
    }
    
    if (locator.startsWith("By.IosNsPredicate: **")) {
    	resBy = MobileBy.iOSNsPredicateString(StringUtils.remove(locator, "By.IosNsPredicate: ") + "[" + index + "]");
    }

    if (locator.startsWith("By.AccessibilityId: ")) {
        resBy = MobileBy.AccessibilityId(StringUtils.remove(locator, "By.AccessibilityId: ") + "[" + index + "]");
    }
    return resBy;
}
 
源代码16 项目: Selenium-Foundation   文件: ByType.java
/**
 * Get the underlying value of the specified Selenium locator
 * 
 * @param locator Selenium locator
 * @return value extracted from the specified locator
 */
private static String valueOf(final By locator) {
    String str = locator.toString();
    int i = str.indexOf(':');
    return str.substring(i + 1).trim();
}
 
源代码17 项目: webtester-core   文件: Identification.java
/**
 * Create an {@link Identification identification} using the given Selenium
 * {@link By}. This constructor is intended to be used in cases where an
 * existing {@link By} has to be transformed into an identification.
 *
 * @param seleniumBy the {@link By} to store
 * @since 0.9.9
 */
public Identification(By seleniumBy) {
    this.seleniumBy = seleniumBy;
    this.toStringMessage = seleniumBy.toString();
}