当前位置: 首页>>代码示例>>Java>>正文


Java By.ById方法代码示例

本文整理汇总了Java中org.openqa.selenium.By.ById方法的典型用法代码示例。如果您正苦于以下问题:Java By.ById方法的具体用法?Java By.ById怎么用?Java By.ById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openqa.selenium.By的用法示例。


在下文中一共展示了By.ById方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: cssLocatorFor

import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
 * Get the CSS locator string that reproduces the specified Selenium locator
 * 
 * @param locator Selenium locator
 * @return CSS locator string; 'null' if unconvertible
 */
public static String cssLocatorFor(By locator) {
    
    String val = valueOf(locator);
    
    if (locator instanceof By.ByClassName) {
        return "." + val;
    } else if (locator instanceof By.ByCssSelector) {
        return val;
    } else if (locator instanceof By.ById) {
        return "#" + val;
    } else if (locator instanceof By.ByLinkText) {
        // unsupported
    } else if (locator instanceof By.ByName) {
        return "[name=" + val + "]";
    } else if (locator instanceof By.ByPartialLinkText) {
        // unsupported
    } else if (locator instanceof By.ByTagName) {
        return val;
    } else if (locator instanceof By.ByXPath) {
        // unsupported
    }
    
    return null;
}
 
开发者ID:Nordstrom,项目名称:Selenium-Foundation,代码行数:31,代码来源:ByType.java

示例2: xpathLocatorFor

import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
 * Get the XPath locator string that reproduces the specified Selenium locator
 * 
 * @param locator Selenium locator
 * @return XPath locator string; 'null' if unconvertible
 */
public static String xpathLocatorFor(By locator) {
    
    String val = valueOf(locator);
    
    if (locator instanceof By.ByClassName) {
        return ".//*[contains(concat(' ',@class,' '),' " + val + " ')]";
    } else if (locator instanceof By.ByCssSelector) {
        // unsupported
    } else if (locator instanceof By.ById) {
        return ".//*[@id='" + val + "']";
    } else if (locator instanceof By.ByLinkText) {
        return ".//a[.='" + val + "']";
    } else if (locator instanceof By.ByName) {
        return ".//*[@name='" + val + "']";
    } else if (locator instanceof By.ByPartialLinkText) {
        return ".//a[text()[contains(.,'" + val + "')]]";
    } else if (locator instanceof By.ByTagName) {
        return ".//" + val;
    } else if (locator instanceof By.ByXPath) {
        return val;
    }
    
    return null;
}
 
开发者ID:Nordstrom,项目名称:Selenium-Foundation,代码行数:31,代码来源:ByType.java

示例3: convertToSelector

import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
 * ID tokens must begin with a letter ([A-Za-z])
 * and may be followed by any number of letters,
 * digits ([0-9]), hyphens ("-"), underscores ("_"),
 * colons (":"), and periods (".").
 * As a purely practical matter, you may want to avoid certain characters.
 * Periods, colons and '#' have special meaning in CSS selectors.
 */
@Override
public By convertToSelector(String identity) {
    waitAjaxIsFinished();
    By selector = new By.ByCssSelector(identity);
    if (identity.matches("^[a-zA-Z][\\w_-]*$")) {
        selector = new By.ById(identity);
    } else if (identity.startsWith("/") || identity.startsWith("./")) {
        selector = new By.ByXPath(identity);
    }
    return selector;
}
 
开发者ID:tapack,项目名称:satisfy,代码行数:20,代码来源:BaseWebPage.java


注:本文中的org.openqa.selenium.By.ById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。