本文整理汇总了Java中org.openqa.selenium.By.xpath方法的典型用法代码示例。如果您正苦于以下问题:Java By.xpath方法的具体用法?Java By.xpath怎么用?Java By.xpath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openqa.selenium.By
的用法示例。
在下文中一共展示了By.xpath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBy
import org.openqa.selenium.By; //导入方法依赖的package包/类
@Override
public By getBy()
{
By by = null;
if(condition == Locator.EQUAL)
{
by = By.xpath(String.format("//%s[@%s='%s']",
this.tagName, this.getAttrName(), this.getValue()));
}
else if(condition == Locator.LIKE)
{
by = By.xpath(String.format("//%s[contains(@%s,'%s')]",
this.tagName, this.getAttrName(), this.getValue()));
}
return by;
}
示例2: determineLocator
import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
* Determine locator.
*
* @param locator the locator
* @return the by
*/
public By determineLocator(String locator) {
if (locator.startsWith(XPATH)) {
return By.xpath(findLocatorSubstring(locator));
} else if (locator.startsWith("//")) {
return By.xpath(locator);
} else if (locator.startsWith(NAME)) {
return By.name(findLocatorSubstring(locator));
} else if (locator.startsWith(LINK)) {
return By.linkText(findLocatorSubstring(locator));
} else if (locator.startsWith(ID)) {
return By.id(findLocatorSubstring(locator));
} else {
return By.id(locator);
}
}
示例3: get
import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
* Retourne un selecteur selenium à partir d'un type et d'une valeur sous forme de String. Les différents sélecteur disponible sont.
* <ul>
* <li>id</li>
* <li>name</li>
* <li>className</li>
* <li>xpath</li>
* <li>css</li>
* <li>linkText</li>
* <li>tagName</li>
* <li>partialLinkText</li>
* </ul>
* Retourne null si aucun sélecteur correspondant au type passé en paramètre n'est trouvé.
* @param type
* @param selector
* @return By
*/
public static By get(String type, String selector) {
By by = null;
if ("id".equalsIgnoreCase(type)) {
by = By.id(selector);
} else if ("name".equalsIgnoreCase(type)) {
by = By.name(selector);
} else if ("className".equalsIgnoreCase(type)) {
by = By.className(selector);
} else if ("xpath".equalsIgnoreCase(type)) {
by = By.xpath(selector);
} else if ("css".equalsIgnoreCase(type)) {
by = By.cssSelector(selector);
} else if ("linkText".equalsIgnoreCase(type)) {
by = By.linkText(selector);
} else if ("tagName".equalsIgnoreCase(type)) {
by = By.tagName(selector);
} else if ("partialLinkText".equalsIgnoreCase(type)) {
by = By.partialLinkText(selector);
}
return by;
}
示例4: byElement
import org.openqa.selenium.By; //导入方法依赖的package包/类
@Override
public By byElement(IElement element) {
if (StringUtils.isEmpty(element.getId())) {
return By.xpath(createSearchXpath(element));
} else {
return byId(createFullElementId(element.getId()));
}
}
示例5: getExpectedCondition
import org.openqa.selenium.By; //导入方法依赖的package包/类
private By getExpectedCondition(final String selectorType, final String selector) {
switch (selectorType) {
case BY_XPATH:
return By.xpath(selector);
case BY_CSS:
return By.cssSelector(selector);
case BY_ID:
return By.id(selector);
case BY_LINK_TEXT:
return By.linkText(selector);
}
return By.xpath(selector);
}
示例6: i_navigate_to_site_demo_shop
import org.openqa.selenium.By; //导入方法依赖的package包/类
@Given("^Selenide I navigate to site Demo Shop$")
public void i_navigate_to_site_demo_shop() throws Throwable {
open(PAGE_URL);
By page_title = By.xpath("/html/body/div[4]/div[1]/div[1]/div[1]/a/img");
$(page_title).should(visible);
}
示例7: deleteResourceEditorText
import org.openqa.selenium.By; //导入方法依赖的package包/类
@When("^I erase garbage value \"(.*)\"$")
public void deleteResourceEditorText(final String text) {
// Click the first occurrence of the element only
final String normalizedText = text.charAt(0) == '"' ? text.substring(1, text.length() - 1) : text;
By by = By.xpath("(//pre[contains(@class, 'CodeMirror-line')]//span[text()='" + normalizedText + "'])[1]");
jwalaUi.click(by);
jwalaUi.doubleClick();
jwalaUi.sendKeysViaActions(Keys.BACK_SPACE);
}
示例8: readLocatorArgument
import org.openqa.selenium.By; //导入方法依赖的package包/类
protected By readLocatorArgument(String argName) {
Object argumentValue = readArgument(argName);
if (argumentValue instanceof String) {
Map<String, Object> newArgValue = new HashMap<String, Object>();
newArgValue.put("xpath", argumentValue);
argumentValue = newArgValue;
}
Map<String, Object> argValueAsMap = (Map<String, Object>) argumentValue;
if (argValueAsMap.containsKey("xpath")) {
if (argValueAsMap.get("xpath").toString().contains("''")) {
return By.xpath(argValueAsMap.get("xpath").toString().replace("''", "'"));
} else {
return By.xpath(argValueAsMap.get("xpath").toString());
}
} else if (argValueAsMap.containsKey("id")) {
return By.id(argValueAsMap.get("id").toString());
} else if (argValueAsMap.containsKey("name")) {
return By.name(argValueAsMap.get("name").toString());
} else {
throw new RuntimeException("Provide at least 1 identifier for the object by populating at least 1 of the following properties: xpath, id, name.");
}
}
示例9: getNestedElement
import org.openqa.selenium.By; //导入方法依赖的package包/类
public By getNestedElement(IElement parent, IElement nested) {
return By.xpath(createSearchXpath(parent) + createSearchXpath(nested));
}
示例10: getNestedElements
import org.openqa.selenium.By; //导入方法依赖的package包/类
public By getNestedElements(IElement parent, IElement nested) {
return By.xpath(createSearchXpath(parent) + createSearchXpath(nested));
}
示例11: for_text_exact
import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
* Return a static text locator by exact text *
*/
public static By for_text_exact(String text) {
return By.xpath("//UIAStaticText[@visible=\"true\" and (@name=\"" + text
+ "\" or @hint=\"" + text + "\" or @label=\"" + text
+ "\" or @value=\"" + text + "\")]");
}
示例12: for_text
import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
* Return a static text locator by xpath index *
*/
public static By for_text(int xpathIndex) {
return By.xpath("//UIAStaticText[" + xpathIndex + "]");
}
示例13: getLinkByXpath
import org.openqa.selenium.By; //导入方法依赖的package包/类
@Deprecated
public static By getLinkByXpath(String linkText) {
return By.xpath("//a[text()='" + linkText + "']");
}
示例14: getBy
import org.openqa.selenium.By; //导入方法依赖的package包/类
@Override
public By getBy()
{
return By.xpath(getValue());
}
示例15: find
import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
* Return a By instance, which is used by findElement()/findElements()
* method to retrieve the element(s). The locators in object repository are
* specified as locator_name=LocatorStrategy,ActualLocatorValue, where
* LocatorStrategy can be 'ID', 'NAME',
* 'CSS_SELECTOR','XPATH','LINK_TEXT','PARTIAL_LINK_TEXT', 'CLASS_NAME',
* 'TAG_NAME'. Ex. mail_link=XPATH,//a[text()='Mail'].
*
* @param locator
* - locator name in object repository
* @return - By instance
* @throws PropertyNotFoundException
* - throw this exception when declared locator is not found in
* object repository
* @throws InvalidLocatorStrategyException
* - throw this exception when locator strategy is wrong. Valid
* locator strategies are 'ID', 'XPATH', 'NAME', 'CSS_SELECTOR',
* 'CLASS_NAME', 'LINK_TEXT', 'PARTIAL_LINK_TEXT' and 'TAG_NAME'
*/
public static By find(String locator) throws PropertyNotFoundException, InvalidLocatorStrategyException
{
locator = props.getProperty(locator);
if (locator.isEmpty() || locator == null)
{
throw new PropertyNotFoundException("Locator value can not be null or empty!");
}
LocatorStrategy strategy = LocatorStrategy.valueOf(locator.split(",")[0]);
String actualLocator = locator.split(",")[1];
By by = null;
switch (strategy)
{
case ID:
by = By.id(actualLocator);
break;
case XPATH:
by = By.xpath(actualLocator);
break;
case NAME:
by = By.name(actualLocator);
break;
case TAG_NAME:
by = By.tagName(actualLocator);
break;
case CSS_SELECTOR:
by = By.cssSelector(actualLocator);
break;
case CLASS_NAME:
by = By.className(actualLocator);
break;
case LINK_TEXT:
by = By.linkText(actualLocator);
break;
case PARTIAL_LINK_TEXT:
by = By.partialLinkText(actualLocator);
break;
default:
throw new InvalidLocatorStrategyException("Unknown locator strategy '" + strategy + "'");
}
return by;
}