当前位置: 首页>>代码示例>>Java>>正文


Java By.className方法代码示例

本文整理汇总了Java中org.openqa.selenium.By.className方法的典型用法代码示例。如果您正苦于以下问题:Java By.className方法的具体用法?Java By.className怎么用?Java By.className使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openqa.selenium.By的用法示例。


在下文中一共展示了By.className方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:Nonorc,项目名称:saladium,代码行数:39,代码来源:BySelec.java

示例2: executeAfterJSPreconditionHasBeenSatisfied

import org.openqa.selenium.By; //导入方法依赖的package包/类
@Override
public void executeAfterJSPreconditionHasBeenSatisfied(WebDriver driver, ReplayingState state) {
    By elementsLocator = By.className(initialCollectorClass);
    List<WebElement> webElements = driver.findElements(elementsLocator);

    Optional<WebElement> webElementOptional = webElements.stream()
            .filter(this::elementTextIsEqualToAndIsDisplayed)
            .findFirst();

    if (!webElementOptional.isPresent()) {
        throw new ElementNotSelectableException("Element with class "
                + initialCollectorClass
                + " and text " + text + " was not found" );
    }

    webElementOptional.get().click();
}
 
开发者ID:hristo-vrigazov,项目名称:bromium,代码行数:18,代码来源:ClickClassByText.java

示例3: throwsExceptionIfNoSuitableElementsAreFound

import org.openqa.selenium.By; //导入方法依赖的package包/类
@Test
public void throwsExceptionIfNoSuitableElementsAreFound() {
    WebElement incorrectWebElement = mock(WebElement.class);
    when(incorrectWebElement.getAttribute(INNER_HTML)).thenReturn("sometATPhing");
    when(incorrectWebElement.isDisplayed()).thenReturn(true);

    List<WebElement> webElements = new ArrayList<>();
    webElements.add(incorrectWebElement);

    By elementsLocator = By.className(initialCollectorClass);
    WebDriver webDriver = mock(WebDriver.class);
    when(webDriver.findElements(elementsLocator)).thenReturn(webElements);

    ClickClassByText clickClassByText = new ClickClassByText(initialCollectorClass, text, eventName, expectsHttp);
    thrown.expect(ElementNotSelectableException.class);
    clickClassByText.executeAfterJSPreconditionHasBeenSatisfied(webDriver, mock(ReplayingState.class));
}
 
开发者ID:hristo-vrigazov,项目名称:bromium,代码行数:18,代码来源:ClickClassByTextTest.java

示例4: selectDropDownValue

import org.openqa.selenium.By; //导入方法依赖的package包/类
protected void selectDropDownValue(By locator) {
    System.out.println("INSIDE THE METHOD - SELECTDROPDOWNVALUE");
    //Click on dropdown to open list.
    MobileElement element = getElement(locator);
    element.click();

    By locator1 = By.className("android.widget.TextView");
    //By.xpath("//android.widget.TextView[@text='Medium']");
    //MobileElement element1 = findElement(locator1, 180);
    //element1.click();

    //Locate all drop down list elements 
    List dropList = driver.findElements(locator1);
    //Extract text from each element of drop down list one by one.  
    for (int i = 0; i < dropList.size(); i++) {
        MobileElement listItem = (MobileElement) dropList.get(i);
        System.out.println(listItem.getText());
    }

}
 
开发者ID:mcdcorp,项目名称:opentest,代码行数:21,代码来源:AppiumTestAction.java

示例5: getLocator

import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
 * This method read a application descriptor file and return a {@link org.openqa.selenium.By} object (xpath, id, link ...).
 *
 * @param applicationKey
 *            Name of application. Each application has its fair description file.
 * @param code
 *            Name of element on the web Page.
 * @param args
 *            list of description (xpath, id, link ...) for code.
 * @return a {@link org.openqa.selenium.By} object (xpath, id, link ...)
 */
public static By getLocator(String applicationKey, String code, Object... args) {
    By locator = null;
    logger.debug("getLocator with this application key : {}", applicationKey);
    logger.debug("getLocator with this locator file : {}", Context.iniFiles.get(applicationKey));
    final Ini ini = Context.iniFiles.get(applicationKey);

    final Map<String, String> section = ini.get(code);
    if (section != null) {
        final Entry<String, String> entry = section.entrySet().iterator().next();
        final String selector = String.format(entry.getValue(), args);
        if ("css".equals(entry.getKey())) {
            locator = By.cssSelector(selector);
        } else if ("link".equals(entry.getKey())) {
            locator = By.linkText(selector);
        } else if ("id".equals(entry.getKey())) {
            locator = By.id(selector);
        } else if ("name".equals(entry.getKey())) {
            locator = By.name(selector);
        } else if ("xpath".equals(entry.getKey())) {
            locator = By.xpath(selector);
        } else if ("class".equals(entry.getKey())) {
            locator = By.className(selector);
        } else {
            Assert.fail(entry.getKey() + " NOT implemented!");
        }
    } else {
        Assert.fail(code + " NOT implemented in ini file " + Context.iniFiles.get(applicationKey) + "!");
    }
    return locator;
}
 
开发者ID:NoraUi,项目名称:NoraUi,代码行数:42,代码来源:Utilities.java

示例6: canClickIfThereIsSuitableElement

import org.openqa.selenium.By; //导入方法依赖的package包/类
@Test
public void canClickIfThereIsSuitableElement() {
    WebElement correctWebElement = mock(WebElement.class);
    when(correctWebElement.getAttribute(INNER_HTML)).thenReturn("  ATP ");
    when(correctWebElement.isDisplayed()).thenReturn(true);

    WebElement incorrectWebElement1 = mock(WebElement.class);
    when(incorrectWebElement1.getAttribute(INNER_HTML)).thenReturn("sometATPhing");
    when(incorrectWebElement1.isDisplayed()).thenReturn(true);

    WebElement incorrectWebElement2 = mock(WebElement.class);
    when(incorrectWebElement2.getAttribute(INNER_HTML)).thenReturn(" ATP ");
    when(incorrectWebElement2.isDisplayed()).thenReturn(false);

    WebElement incorrectWebElement3 = mock(WebElement.class);
    when(incorrectWebElement3.getAttribute(INNER_HTML)).thenReturn("sometATPhing");
    when(incorrectWebElement3.isDisplayed()).thenReturn(false);

    List<WebElement> webElements = new ArrayList<>();
    webElements.add(incorrectWebElement1);
    webElements.add(incorrectWebElement2);
    webElements.add(incorrectWebElement3);
    webElements.add(correctWebElement);

    By elementsLocator = By.className(initialCollectorClass);
    WebDriver webDriver = mock(WebDriver.class);
    when(webDriver.findElements(elementsLocator)).thenReturn(webElements);

    ClickClassByText clickClassByText = new ClickClassByText(initialCollectorClass, text, eventName, expectsHttp);
    clickClassByText.executeAfterJSPreconditionHasBeenSatisfied(webDriver, mock(ReplayingState.class));
}
 
开发者ID:hristo-vrigazov,项目名称:bromium,代码行数:32,代码来源:ClickClassByTextTest.java

示例7: throwsExceptionIfNoElementsAreFound

import org.openqa.selenium.By; //导入方法依赖的package包/类
@Test
public void throwsExceptionIfNoElementsAreFound() {
    List<WebElement> webElements = new ArrayList<>();

    By elementsLocator = By.className(initialCollectorClass);
    WebDriver webDriver = mock(WebDriver.class);
    when(webDriver.findElements(elementsLocator)).thenReturn(webElements);

    ClickClassByText clickClassByText = new ClickClassByText(initialCollectorClass, text, eventName, expectsHttp);
    thrown.expect(ElementNotSelectableException.class);
    clickClassByText.executeAfterJSPreconditionHasBeenSatisfied(webDriver, mock(ReplayingState.class));
}
 
开发者ID:hristo-vrigazov,项目名称:bromium,代码行数:13,代码来源:ClickClassByTextTest.java

示例8: getByClass

import org.openqa.selenium.By; //导入方法依赖的package包/类
@SProperty(name = "class")
public By getByClass(String className) {
    if (className.contains(" ")) {
        return getByXpath("//*[@className='" + className + "']");
    }
    return By.className(className);
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:8,代码来源:DefaultFindBy.java

示例9: getItemsFromPicklistContainer

import org.openqa.selenium.By; //导入方法依赖的package包/类
private List<String> getItemsFromPicklistContainer(String listContainer) {
    By list = By.className(listContainer);
    WebElement listElement = getRootElement().findElement(list);
    By items = By.className("pickList_listItem");
    List<WebElement> itemElements = listElement.findElements(items);
    return convert(itemElements, toTextValues());
}
 
开发者ID:tapack,项目名称:satisfy,代码行数:8,代码来源:BasePicklistSteps.java

示例10: getObject

import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
 * @param p
 * @param type
 * @param value
 * @return
 */
private By getObject(Properties p, String type, String value) {
	//System.out.println("DEBUG---PropertyName: " + type + "----DEBUG");
	//System.out.println("DEBUG---PropertyValue: " + value + "----DEBUG");
	By toBeReturned = null;
	String str = type.toLowerCase();
	switch(str) {

	case "classname": 
		toBeReturned = By.className(p.getProperty(value));
		break;
	case "css":
		toBeReturned = By.cssSelector(p.getProperty(value));
		break;
	case "id":
		toBeReturned = By.id(p.getProperty(value));
		break;
	case "linktext":
		toBeReturned = By.linkText(p.getProperty(value));
		break;
	case "name":
		toBeReturned = By.name(p.getProperty(value));
		break;
	case "partiallink":
		toBeReturned = By.partialLinkText(p.getProperty(value));
		break;
	case "tagname":
		toBeReturned = By.tagName(p.getProperty(value));
		break;
	case "xpath":
		break;
	default:
		//TODO
		
	}
	
	return toBeReturned;
}
 
开发者ID:mattecker,项目名称:revature-automation-framework-remastered,代码行数:44,代码来源:WebOperation.java

示例11: getBy

import org.openqa.selenium.By; //导入方法依赖的package包/类
@Override
public By getBy()
{
	return By.className(getValue());
}
 
开发者ID:LinuxSuRen,项目名称:phoenix.webui.framework,代码行数:6,代码来源:SeleniumCssLocator.java

示例12: 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;
}
 
开发者ID:pradeeptaswain,项目名称:oldmonk,代码行数:66,代码来源:ElementFinder.java

示例13: for_tags

import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
 * Return a tag name locator *
 */
public static By for_tags(String tagName) {
    return By.className(tagName);
}
 
开发者ID:QualityWorksCG,项目名称:Appium-Sample,代码行数:7,代码来源:Helpers.java

示例14: clickOnPicklistButtonByClassName

import org.openqa.selenium.By; //导入方法依赖的package包/类
private void clickOnPicklistButtonByClassName(String className) {
    By button = By.className(className);
    getRootElement().findElement(button).click();
}
 
开发者ID:tapack,项目名称:satisfy,代码行数:5,代码来源:BasePicklistSteps.java

示例15: for_tags

import org.openqa.selenium.By; //导入方法依赖的package包/类
/**
 * Return a tag name locator *
 */
public static By for_tags(String tagName) {
  return By.className(tagName);
}
 
开发者ID:GSMATerminals,项目名称:Smartphone-Performance-Test-Case-Guideline-Public,代码行数:7,代码来源:Helpers.java


注:本文中的org.openqa.selenium.By.className方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。