Java Code Examples for org.openqa.selenium.By#ByClassName

The following examples show how to use org.openqa.selenium.By#ByClassName . 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: ByType.java    From Selenium-Foundation with Apache License 2.0 6 votes vote down vote up
/**
 * Get the CSS locator string that reproduces the specified Selenium locator
 * 
 * @param locator Selenium locator
 * @return CSS locator string; 'null' if unconvertible
 */
@SuppressWarnings("squid:S1142")
public static String cssLocatorFor(final 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) {
        LOGGER.warn(UNSUPPORTED_FOR_CSS, "ByLinkText");
    } else if (locator instanceof By.ByName) {
        return "[name=" + val + "]";
    } else if (locator instanceof By.ByPartialLinkText) {
        LOGGER.warn(UNSUPPORTED_FOR_CSS, "ByPartialLinkText");
    } else if (locator instanceof By.ByTagName) {
        return val;
    } else if (locator instanceof By.ByXPath) {
        LOGGER.warn(UNSUPPORTED_FOR_CSS, "ByXPath");
    }
    
    return null;
}
 
Example 2
Source File: ByType.java    From Selenium-Foundation with Apache License 2.0 6 votes vote down vote up
/**
 * Get the XPath locator string that reproduces the specified Selenium locator
 * 
 * @param locator Selenium locator
 * @return XPath locator string; 'null' if unconvertible
 */
@SuppressWarnings("squid:S1142")
public static String xpathLocatorFor(final By locator) {
    
    String val = valueOf(locator);
    
    if (locator instanceof By.ByClassName) {
        return ".//*[contains(concat(' ',@class,' '),' " + val + " ')]";
    } else if (locator instanceof By.ByCssSelector) {
        LOGGER.warn(UNSUPPORTED_FOR_XPATH, "ByCssSelector");
    } 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;
}
 
Example 3
Source File: PageBase.java    From SeleniumCucumber with GNU General Public License v3.0 6 votes vote down vote up
private By getFindByAnno(FindBy anno){
	log.info(anno);
	switch (anno.how()) {
	
	case CLASS_NAME:
		return new By.ByClassName(anno.using());
	case CSS:
		return new By.ByCssSelector(anno.using());
	case ID:
		return new By.ById(anno.using());
	case LINK_TEXT:
		return new By.ByLinkText(anno.using());
	case NAME:
		return new By.ByName(anno.using());
	case PARTIAL_LINK_TEXT:
		return new By.ByPartialLinkText(anno.using());
	case XPATH:
		return new By.ByXPath(anno.using());
	default :
		throw new IllegalArgumentException("Locator not Found : " + anno.how() + " : " + anno.using());
	}
}