Java Code Examples for org.openqa.selenium.By#partialLinkText()

The following examples show how to use org.openqa.selenium.By#partialLinkText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertyFileObjectRepositoryManager.java    From qashowcase with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the By locator through reading the object repository.
 * @param key Is in the form of HomePage.LoginLink or ${pageName}.${elementName}
 * @return A By locator that can be used to locate WebElement(s).
 */
public By getByFromObjectRepositoryLocator(String key) {
    By by = null;
    String locatorType = getLocatorTypeString(key);
    String locatorString = getLocatorValueString(key);
    if(locatorType != null && locatorString != null) {
        if(locatorType.equalsIgnoreCase("LINK_TEXT")) {
            by = By.linkText(locatorString);
        } else if (locatorType.equalsIgnoreCase("PARTIAL_LINK_TEXT")) {
            by = By.partialLinkText(locatorString);
        } else if (locatorType.equalsIgnoreCase("NAME")) {
            by = By.name(locatorString);
        } else if (locatorType.equalsIgnoreCase("ID")) {
            by = By.id(locatorString);
        } else if (locatorType.equalsIgnoreCase("CLASS_NAME")) {
            by = By.className(locatorString);
        } else if (locatorType.equalsIgnoreCase("TAG_NAME")) {
            by = By.tagName(locatorString);
        } else if (locatorType.equalsIgnoreCase("CSS_SELECTOR")) {
            by = By.cssSelector(locatorString);
        } else if (locatorType.equalsIgnoreCase("XPATH")) {
            by = By.xpath(locatorString);
        }
    }
    return by;
}
 
Example 2
Source File: Hook.java    From candybean with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * A helper method to convert Hook to By
 * @param hook	The hook that specifies a web element
 * @return		The converted By
 * @throws CandybeanException
 */
public static By getBy(Hook hook) throws CandybeanException {
	switch (hook.hookStrategy) {
		case CSS:
			return By.cssSelector(hook.hookString);
		case XPATH:
			return By.xpath(hook.hookString);
		case ID:
			return By.id(hook.hookString);
		case NAME:
			return By.name(hook.hookString);
		case LINK:
			return By.linkText(hook.hookString);
		case PLINK:
			return By.partialLinkText(hook.hookString);
		case CLASS:
			return By.className(hook.hookString);
		case TAG:
			return By.tagName(hook.hookString);
		default:
			throw new CandybeanException("Strategy type not recognized.");
	}
}
 
Example 3
Source File: BySelector.java    From selenium with Apache License 2.0 6 votes vote down vote up
public By pickFrom(String method, String selector) {
  if ("class name".equals(method)) {
    return By.className(selector);
  } else if ("css selector".equals(method)) {
    return By.cssSelector(selector);
  } else if ("id".equals(method)) {
    return By.id(selector);
  } else if ("link text".equals(method)) {
    return By.linkText(selector);
  } else if ("partial link text".equals(method)) {
    return By.partialLinkText(selector);
  } else if ("name".equals(method)) {
    return By.name(selector);
  } else if ("tag name".equals(method)) {
    return By.tagName(selector);
  } else if ("xpath".equals(method)) {
    return By.xpath(selector);
  } else {
    throw new WebDriverException("Cannot find matching element locator to: " + method);
  }
}
 
Example 4
Source File: BaseUI.java    From movieapp-dialog with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a locator string with a known prefix to a By object
 * @param myLocator
 * 		Supported locators:
 * 			xpath - "//"
 * 			   id - "id="
 * 	 css selector - "css="
 * 			xpath - "xpath="
 * 	 	 linktext - "link="
 * 		     name - "name="
 *linkpartialtext - "linkpartial="
 * @return By object extracted from given string locator
 */
private static By byFromLocator(String locator) {
	if (locator.startsWith("//")) {
		return By.xpath(locator);
	}
	if (locator.startsWith("id=")) {
		return By.id(locator.replaceFirst("id=", ""));
	}
	if (locator.startsWith("css=")) {
		return By.cssSelector(locator.replaceFirst("css=", ""));
	}
	if (locator.startsWith("xpath=")) {
		return By.xpath(locator.replaceFirst("xpath=", ""));
	}
	if (locator.startsWith("name=")) {
		return By.name(locator.replaceFirst("name=", ""));
	}
	if (locator.startsWith("link=")) {
		return By.linkText(locator.replaceFirst("link=", ""));
	}
	if (locator.startsWith("linkpartial=")) {
		return By.partialLinkText(locator.replaceFirst("linkpartial=", ""));
	}
	throw new IllegalArgumentException("Locator not supported: "
			+ locator);
}
 
Example 5
Source File: HTMLElement.java    From at.info-knowledge-base with MIT License 5 votes vote down vote up
public final void initElement(final SearchBy elementSearchCriteria, final String elementValue) {

        switch (elementSearchCriteria) {
            case ID:
                locator = By.id(elementValue);
                break;
            case XPATH:
                locator = By.xpath(elementValue);
                break;
            case LINK_TEXT:
                locator = By.linkText(elementValue);
                break;
            case CLASS_NAME:
                locator = By.className(elementValue);
                break;
            case CSS_SELECTOR:
                locator = By.cssSelector(elementValue);
                break;
            case TAG_NAME:
                locator = By.tagName(elementValue);
                break;
            case NAME:
                locator = By.name(elementValue);
                break;
            case PARTIAL_LINK_TEXT:
                locator = By.partialLinkText(elementValue);
                break;
        }
    }
 
Example 6
Source File: BaseAction.java    From PatatiumWebUi with Apache License 2.0 5 votes vote down vote up
static By getBy (ByType byType,Locator locator)
{
	switch(byType)
	{
		case id:
			return By.id(locator.getElement());
		case cssSelector:
			return By.cssSelector(locator.getElement());
		case name:
			return By.name(locator.getElement());
		case xpath:
			return By.xpath(locator.getElement());
		case className:
			return By.className(locator.getElement());
		case tagName:
			return By.tagName(locator.getElement());
		case linkText:
			return By.linkText(locator.getElement());
		case partialLinkText:
			return By.partialLinkText(locator.getElement());
		//return null也可以放到switch外面
		default:
			return null;
	}


}
 
Example 7
Source File: BaseAction.java    From PatatiumAppUi with GNU General Public License v2.0 5 votes vote down vote up
static By getBy (ByType byType,Locator locator)
{
	switch(byType)
	{
		case id:
			return By.id(locator.getElement());
		case cssSelector:
			return By.cssSelector(locator.getElement());
		case name:
			return By.name(locator.getElement());
		case xpath:
			return By.xpath(locator.getElement());
		case className:
			return By.className(locator.getElement());
		case tagName:
			return By.tagName(locator.getElement());
		case linkText:
			return By.linkText(locator.getElement());
		case partialLinkText:
			return By.partialLinkText(locator.getElement());
		//return null也可以放到switch外面
		default:
			return null;
	}


}
 
Example 8
Source File: AbstractFindByBuilder.java    From selenium with Apache License 2.0 5 votes vote down vote up
protected By buildByFromShortFindBy(FindBy findBy) {
  if (!"".equals(findBy.className())) {
    return By.className(findBy.className());
  }

  if (!"".equals(findBy.css())) {
    return By.cssSelector(findBy.css());
  }

  if (!"".equals(findBy.id())) {
    return By.id(findBy.id());
  }

  if (!"".equals(findBy.linkText())) {
    return By.linkText(findBy.linkText());
  }

  if (!"".equals(findBy.name())) {
    return By.name(findBy.name());
  }

  if (!"".equals(findBy.partialLinkText())) {
    return By.partialLinkText(findBy.partialLinkText());
  }

  if (!"".equals(findBy.tagName())) {
    return By.tagName(findBy.tagName());
  }

  if (!"".equals(findBy.xpath())) {
    return By.xpath(findBy.xpath());
  }

  // Fall through
  return null;
}
 
Example 9
Source File: ExtendedWebElement.java    From carina with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 10
Source File: LocalizedAnnotations.java    From carina with Apache License 2.0 4 votes vote down vote up
private By createBy(String locator) {
    if (locator.startsWith("id=")) {
        return By.id(StringUtils.remove(locator, "id="));
    } else if (locator.startsWith("name=")) {
        return By.name(StringUtils.remove(locator, "name="));
    } else if (locator.startsWith("xpath=")) {
        return By.xpath(StringUtils.remove(locator, "xpath="));
    } else if (locator.startsWith("linkText=")) {
        return By.linkText(StringUtils.remove(locator, "linkText="));
    } else if (locator.startsWith("partialLinkText=")) {
        return By.partialLinkText(StringUtils.remove(locator, "partialLinkText="));
    } else if (locator.startsWith("cssSelector=")) {
        return By.cssSelector(StringUtils.remove(locator, "cssSelector="));
    } else if (locator.startsWith("css=")) {
        return By.cssSelector(StringUtils.remove(locator, "css="));
    } else if (locator.startsWith("tagName=")) {
        return By.tagName(StringUtils.remove(locator, "tagName="));
    } else if (locator.startsWith("className=")) {
        return By.className(StringUtils.remove(locator, "className="));
    } else if (locator.startsWith("By.id: ")) {
        return By.id(StringUtils.remove(locator, "By.id: "));
    } else if (locator.startsWith("By.name: ")) {
        return By.name(StringUtils.remove(locator, "By.name: "));
    } else if (locator.startsWith("By.xpath: ")) {
        return By.xpath(StringUtils.remove(locator, "By.xpath: "));
    } else if (locator.startsWith("By.linkText: ")) {
        return By.linkText(StringUtils.remove(locator, "By.linkText: "));
    } else if (locator.startsWith("By.partialLinkText: ")) {
        return By.partialLinkText(StringUtils.remove(locator, "By.partialLinkText: "));
    } else if (locator.startsWith("By.css: ")) {
        return By.cssSelector(StringUtils.remove(locator, "By.css: "));
    } else if (locator.startsWith("By.cssSelector: ")) {
        return By.cssSelector(StringUtils.remove(locator, "By.cssSelector: "));
    } else if (locator.startsWith("By.className: ")) {
        return By.className(StringUtils.remove(locator, "By.className: "));
    } else if (locator.startsWith("By.tagName: ")) {
        return By.tagName(StringUtils.remove(locator, "By.tagName: "));
    }       

    throw new RuntimeException(String.format("Unable to generate By using locator: '%s'!", locator));
}
 
Example 11
Source File: LinkBy.java    From hsac-fitnesse-fixtures with Apache License 2.0 4 votes vote down vote up
public Partial(String partialText) {
    super(By.partialLinkText(partialText),
            new XPathBy(".//a[descendant-or-self::text()[contains(normalized(.),'%s')]]", partialText));
}
 
Example 12
Source File: PartialLinkTextByConverter.java    From webtester-core with Apache License 2.0 4 votes vote down vote up
@Override
public By toBy(String value) {
    return By.partialLinkText(value);
}
 
Example 13
Source File: Locator.java    From seleniumtestsframework with Apache License 2.0 4 votes vote down vote up
public static By locateByPartialLinkText(final String partialLinkText) {
    return By.partialLinkText(partialLinkText);
}
 
Example 14
Source File: LocatorUtil.java    From qaf with MIT License 4 votes vote down vote up
public static By getBy(String loc, PropertyUtil props) {
	Gson gson = new Gson();
	loc = props.getSubstitutor().replace(loc);
	loc = props.getString(loc, loc);
	JsonElement element = JSONUtil.getGsonElement(loc);
	if ((null != element) && element.isJsonObject()) {
		Object obj = gson.fromJson(element, Map.class).get("locator");

		loc = obj instanceof String ? (String) obj :

				gson.toJson(obj);
	}
	element = JSONUtil.getGsonElement(loc);
	if ((null != element) && element.isJsonArray()) {
		String[] locs = new Gson().fromJson(element, String[].class);
		return new ByAny(locs);
	}
	if (loc.startsWith("//")) {
		return By.xpath(loc);
	} else if (loc.indexOf("=") > 0) {
		String parts[] = loc.split("=", 2);
		if (parts[0].equalsIgnoreCase("key") || parts[0].equalsIgnoreCase("property")) {
			String val = props.getSubstitutor().replace(parts[1]);
			return getBy(props.getString(val, val), props);
		}
		if (parts[0].equalsIgnoreCase("jquery")) {
			return new ByJQuery(parts[1]);
		}
		if (parts[0].equalsIgnoreCase("extDom")) {
			return new ByExtDomQuery(parts[1]);
		}
		if (parts[0].equalsIgnoreCase("extComp")) {
			return new ByExtCompQuery(parts[1]);
		}
		if (parts[0].equalsIgnoreCase("name")) {
			return By.name(parts[1]);
		} else if (parts[0].equalsIgnoreCase("id")) {
			return By.id(parts[1]);
		} else if (parts[0].equalsIgnoreCase("xpath")) {
			return By.xpath(parts[1]);
		} else if (parts[0].equalsIgnoreCase("css")) {
			return By.cssSelector(parts[1]);
		} else if (parts[0].equalsIgnoreCase("link") || parts[0].equalsIgnoreCase("linkText")) {
			return By.linkText(parts[1]);
		} else if (parts[0].equalsIgnoreCase("partialLink") || parts[0].equalsIgnoreCase("partialLinkText")) {
			return By.partialLinkText(parts[1]);
		} else if (parts[0].equalsIgnoreCase("className")) {
			return By.className(parts[1]);
		} else if (parts[0].equalsIgnoreCase("tagName")) {
			return By.tagName(parts[1]);
		} else {
			return new ByCustom(parts[0], parts[1]);
		}
	} else {
		return By.xpath(String.format("//*[@name='%s' or @id='%s' or @value='%s']", loc, loc, loc));
	}
}
 
Example 15
Source File: PartialLinkText.java    From webtester2-core with Apache License 2.0 4 votes vote down vote up
@Override
public By createBy(String value) {
    return By.partialLinkText(value);
}
 
Example 16
Source File: DefaultFindBy.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 4 votes vote down vote up
@SProperty(name = "partialLinkText")
public By getByPartialLinkText(String linkText) {
    return By.partialLinkText(linkText);
}
 
Example 17
Source File: AppiumTestAction.java    From opentest with MIT License 4 votes vote down vote up
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("id")) {
        return By.id(argValueAsMap.get("id").toString());
    } else if (argValueAsMap.containsKey("accessibilityId")) {
        return MobileBy.AccessibilityId(argValueAsMap.get("accessibilityId").toString());
    } else if (argValueAsMap.containsKey("predicate")) {
        return MobileBy.iOSNsPredicateString(argValueAsMap.get("predicate").toString());
    } else if (argValueAsMap.containsKey("iosClassChain")) {
        return MobileBy.iOSClassChain(argValueAsMap.get("iosClassChain").toString());
    } else if (argValueAsMap.containsKey("androidUiAutomator")) {
        return MobileBy.AndroidUIAutomator(argValueAsMap.get("androidUiAutomator").toString());
    } else if (argValueAsMap.containsKey("name")) {
        return By.name(argValueAsMap.get("name").toString());
    } else if (argValueAsMap.containsKey("css")) {
        return By.cssSelector(argValueAsMap.get("css").toString());
    } else if (argValueAsMap.containsKey("class")) {
        return By.className(argValueAsMap.get("class").toString());
    } else if (argValueAsMap.containsKey("tag")) {
        return By.tagName(argValueAsMap.get("tag").toString());
    } else if (argValueAsMap.containsKey("linkText")) {
        return By.linkText(argValueAsMap.get("linkText").toString());
    } else if (argValueAsMap.containsKey("partialLinkText")) {
        return By.partialLinkText(argValueAsMap.get("partialLinkText").toString());
    } else if (argValueAsMap.containsKey("xpath")) {
        String xpath = argValueAsMap.get("xpath").toString().replace("''", "'");
        return By.xpath(xpath);
    } else if (argValueAsMap.containsKey("image")) {
        String imageBase64 = argValueAsMap.get("image").toString();
        return MobileBy.image(imageBase64); // TO DO continue implementation
    } else {
        throw new RuntimeException(
                "You must provide at least one valid identification method the locator "
                + "object by populating at least 1 of the following properties: id, name, "
                + "css, class, tag, linkText, partialLinkText, xpath.");
    }
}
 
Example 18
Source File: SeleniumPartialLinkTextLocator.java    From phoenix.webui.framework with Apache License 2.0 4 votes vote down vote up
@Override
public By getBy()
{
	return By.partialLinkText(getValue());
}