本文整理汇总了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;
}
示例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;
}
示例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;
}