本文整理汇总了Java中org.openqa.selenium.By.ByCssSelector方法的典型用法代码示例。如果您正苦于以下问题:Java By.ByCssSelector方法的具体用法?Java By.ByCssSelector怎么用?Java By.ByCssSelector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openqa.selenium.By
的用法示例。
在下文中一共展示了By.ByCssSelector方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: find
import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
* find web element identified by css selector
*
* Warning: DO NOT USE this class in @PARALLEL mode
*
* @param cssSelector
* @throws Exception
*/
public void find(String cssSelector) throws Exception {
a1 = new Date();
By by = new By.ByCssSelector(cssSelector);
if (TestExecutionController.SEQUENTIAL.equals(mode)) {
foundFields = testExecController.findBy(by);
} else {
Assert.assertTrue(TestExecutionController.SEQUENTIAL.equals(mode),
"Default Step Def <find> cannot be used in " + mode + " mode");
}
a2 = new Date();
System.out.println("<find> in " + mode + " mode took " + (a2.getTime() - a1.getTime()) + " milliseconds");
}
示例4: 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;
}
示例5: RobustElementWrapper
import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
* Main robust web element constructor
*
* @param element element reference to be wrapped (may be 'null')
* @param context element search context
* @param locator element locator
* @param index element index
*/
public RobustElementWrapper(WebElement element, WrapsContext context, By locator, 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();
}
}