org.openqa.selenium.By - java examples

Here are the examples of the java api org.openqa.selenium.By taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : WebDriverByUtils.java
Copyright GNU General Public License v3.0
Author : epam
public static By trimRoot(By by) {
    String byLocator = getByLocator(by).replace("*root*", " ").trim();
    return getByFunc(by).apply(byLocator);
}

19 View Complete Implementation : GetElementModule.java
Copyright GNU General Public License v3.0
Author : epam
public void setLocator(By locator) {
    byLocator = locator;
}

19 View Complete Implementation : WebDriverByUtils.java
Copyright GNU General Public License v3.0
Author : epam
public static By fillByMsgTemplate(By by, Object... args) {
    String byLocator = getByLocator(by);
    try {
        byLocator = MessageFormat.format(byLocator, args);
    } catch (Exception ex) {
        throw new RuntimeException(getBadLocatorMsg(byLocator, args));
    }
    return getByFunc(by).apply(byLocator);
}

19 View Complete Implementation : WebDriverByUtils.java
Copyright GNU General Public License v3.0
Author : epam
public static boolean containsRoot(By by) {
    return by != null && by.toString().contains(": *root*");
}

19 View Complete Implementation : BaseElement.java
Copyright GNU General Public License v3.0
Author : epam
public String printContext() {
    By locator;
    BaseElement parent;
    String parentContext;
    return getParent() == null || !isClreplaced(getParent().getClreplaced(), BaseElement.clreplaced) || (locator = (parent = (BaseElement) getParent()).getLocator()) == null ? "" : ((parentContext = parent.printContext()).equals("")) ? locator.toString() : locator + "; " + parentContext;
}

19 View Complete Implementation : WebDriverByUtils.java
Copyright GNU General Public License v3.0
Author : epam
public static By copyBy(By by) {
    String byLocator = getByLocator(by);
    return getByFunc(by).apply(byLocator);
}

19 View Complete Implementation : GetElementModule.java
Copyright GNU General Public License v3.0
Author : epam
private String printShortBy(By by) {
    return String.format("%s='%s'", getByStr(by), getByLocator(by));
}

19 View Complete Implementation : WebDriverByUtils.java
Copyright GNU General Public License v3.0
Author : epam
public static By fillByTemplate(By by, Object... args) {
    String byLocator = getByLocator(by);
    if (!byLocator.contains("%"))
        throw new RuntimeException(getBadLocatorMsg(byLocator, args));
    try {
        byLocator = format(byLocator, args);
    } catch (Exception ex) {
        throw new RuntimeException(getBadLocatorMsg(byLocator, args));
    }
    return getByFunc(by).apply(byLocator);
}

19 View Complete Implementation : SimpleTablePage.java
Copyright GNU General Public License v3.0
Author : epam
public ITable getTable(By rowHeader, By columnHeader, By row, By column, int rowStartIndex, int columnStartIndex) {
    simpleTable = new Table(rowHeader, columnHeader, row, column, rowStartIndex, columnStartIndex);
    // simpleTable.avatar.byLocator = By.xpath("*//table");
    return simpleTable;
}

19 View Complete Implementation : Search.java
Copyright GNU General Public License v3.0
Author : epam
public void setup(Field field) {
    if (!fieldHasAnnotation(field, JSearch.clreplaced, ISearch.clreplaced))
        return;
    JSearch jSearch = field.getAnnotation(JSearch.clreplaced);
    By root = findByToBy(jSearch.root());
    By input = findByToBy(jSearch.input());
    By searchButton = findByToBy(jSearch.searchButton());
    By suggestions = findByToBy(jSearch.suggestions());
    if (input == null)
        input = findByToBy(jSearch.jInput());
    if (searchButton == null)
        searchButton = findByToBy(jSearch.jSearchButton());
    if (suggestions == null)
        suggestions = findByToBy(jSearch.jSuggestions());
    if (input != null)
        avatar = new GetElementModule(input, this);
    if (searchButton != null)
        this.searchButton = new Button(searchButton);
    if (suggestions != null)
        this.suggestions = new TextList<>(suggestions);
}

19 View Complete Implementation : GetElementModule.java
Copyright GNU General Public License v3.0
Author : epam
private String printShortBy(By by) {
    return String.format("%s='%s'", getByName(by), getByLocator(by));
}

19 View Complete Implementation : Element.java
Copyright GNU General Public License v3.0
Author : epam
public WebElement get(By locator) {
    Element el = new Element(locator);
    el.setParent(this);
    return el.getWebElement();
}

19 View Complete Implementation : WebDriverByUtils.java
Copyright GNU General Public License v3.0
Author : epam
public static By fillByMsgTemplate(By by, Object... args) {
    String byLocator = getByLocator(by);
    try {
        byLocator = MessageFormat.format(byLocator, args);
    } catch (Exception ex) {
        throw new RuntimeException(getBadLocatorMsg(byLocator, args));
    }
    return getByFunc(by).apply(byLocator);
}

19 View Complete Implementation : BaseElement.java
Copyright GNU General Public License v3.0
Author : epam
public BaseElement setAvatar(By byLocator) {
    this.avatar = this.avatar.copy(byLocator);
    return this;
}

19 View Complete Implementation : GetElementModule.java
Copyright GNU General Public License v3.0
Author : epam
public GetElementModule copy(By byLocator) {
    GetElementModule clone = new GetElementModule(byLocator, element);
    clone.localElementSearchCriteria = localElementSearchCriteria;
    clone.frameLocator = frameLocator;
    clone.rootElement = rootElement;
    clone.driverName = driverName;
    clone.element = element;
    clone.webElement = webElement;
    clone.webElements = webElements;
    return clone;
}

19 View Complete Implementation : WebDriverByUtils.java
Copyright GNU General Public License v3.0
Author : epam
public static String getByLocator(By by) {
    String byreplacedtring = by.toString();
    int index = byreplacedtring.indexOf(": ") + 2;
    return byreplacedtring.substring(index);
}

19 View Complete Implementation : AppiumCascadeInit.java
Copyright GNU General Public License v3.0
Author : epam
protected By getNewLocatorFromField(Field field) {
    By byLocator = null;
    if (group == null)
        return findByToBy(field.getAnnotation(FindBy.clreplaced));
    JFindBy jFindBy = field.getAnnotation(JFindBy.clreplaced);
    if (jFindBy != null && group.equals(jFindBy.group()))
        byLocator = AppiumAnnotationsUtil.getFindByLocator(jFindBy);
    return byLocator != null ? byLocator : findByToBy(field.getAnnotation(FindBy.clreplaced));
}

19 View Complete Implementation : WebDriverByUtils.java
Copyright GNU General Public License v3.0
Author : epam
public static boolean containsRoot(By by) {
    return by != null && by.toString().contains(": *root*");
}

19 View Complete Implementation : DesktopApplication.java
Copyright GNU General Public License v3.0
Author : epam
public clreplaced DesktopApplication extends Application {

    public static String appPath;

    public static void setAppPath(String path) {
        appPath = "";
        if (!path.contains(":"))
            appPath = DEFAULT_PATH;
        appPath += path;
    }

    public static By windowId;

    public static <T> void init(Clreplaced<T> applicationClreplaced) {
        if (applicationClreplaced.isAnnotationPresent(WinApp.clreplaced)) {
            String value = applicationClreplaced.getAnnotation(WinApp.clreplaced).value();
            if (isBlank(value))
                value = applicationClreplaced.getAnnotation(WinApp.clreplaced).application();
            if (isNotBlank(value))
                setAppPath(value);
            By windowLocator = findByToBy(applicationClreplaced.getAnnotation(WinApp.clreplaced).windowLocator());
            if (windowLocator != null)
                windowId = windowLocator;
        }
        new WinCascadeInit().initStaticPages(applicationClreplaced, driverFactory.currentDriverName());
        currentSite = applicationClreplaced;
    }
}

19 View Complete Implementation : GetElementModule.java
Copyright GNU General Public License v3.0
Author : epam
private SearchContext getFrameContext(By frame) {
    return getDriver().switchTo().frame(getDriver().findElement(frame));
}

19 View Complete Implementation : WebDriverByUtils.java
Copyright GNU General Public License v3.0
Author : epam
public static By correctXPaths(By byValue) {
    return byValue.toString().contains("By.xpath: //") ? getByFunc(byValue).apply(getByLocator(byValue).replaceFirst("/", "./")) : byValue;
}

19 View Complete Implementation : SimpleTablePage.java
Copyright GNU General Public License v3.0
Author : epam
public ITable getTable(By rowHeader, By columnHeader, int rowStartIndex, int columnStartIndex) {
    simpleTable = new Table(rowHeader, columnHeader, null, null, rowStartIndex, columnStartIndex);
    // simpleTable.avatar.byLocator = By.xpath("*//table");
    return simpleTable;
}

19 View Complete Implementation : WinCascadeInit.java
Copyright GNU General Public License v3.0
Author : epam
@Override
protected IBaseElement getElementsRules(Field field, String driverName, Clreplaced<?> type, String fieldName) throws IllegalAccessException, InstantiationException {
    By newLocator = getNewLocator(field);
    BaseElement instance = null;
    if (type.isInterface())
        type = MapInterfaceToElement.getClreplacedFromInterface(type);
    if (type != null) {
        instance = (BaseElement) type.newInstance();
        instance.avatar.setByLocator(newLocator);
    }
    if (instance == null)
        throw exception("Unknown interface of field %s. Add relation interface -> clreplaced in VIElement.InterfaceTypeMap", fieldName);
    instance.avatar.setDriverName(driverName);
    return instance;
}

19 View Complete Implementation : JdiStatic.java
Copyright GNU General Public License v3.0
Author : epam
public static J $(By locator) {
    return new J(locator);
}

19 View Complete Implementation : WebDriverByUtils.java
Copyright GNU General Public License v3.0
Author : epam
public static By fillByTemplate(By by, Object... args) {
    String byLocator = getByLocator(by);
    if (!byLocator.contains("%"))
        throw new RuntimeException(getBadLocatorMsg(byLocator, args));
    try {
        byLocator = format(byLocator, args);
    } catch (Exception ex) {
        throw new RuntimeException(getBadLocatorMsg(byLocator, args));
    }
    return getByFunc(by).apply(byLocator);
}

19 View Complete Implementation : WebDriverByUtils.java
Copyright GNU General Public License v3.0
Author : epam
public static String getByName(By by) {
    Matcher m = Pattern.compile("By\\.(?<locator>.*):.*").matcher(by.toString());
    if (m.find())
        return m.group("locator");
    throw new RuntimeException("Can't get By name for: " + by);
}

19 View Complete Implementation : Dropdown.java
Copyright GNU General Public License v3.0
Author : epam
public void setUp(By expandBy, By elementsByName) {
    if (expandBy != null)
        avatar.setByLocator(expandBy);
    dropdownManager = new DropdownManager<>(this, elementsByName);
}

19 View Complete Implementation : TreeDropdown.java
Copyright GNU General Public License v3.0
Author : epam
@Override
public void setup(Field field) {
    if (!fieldHasAnnotation(field, JTree.clreplaced, IDropDown.clreplaced))
        return;
    JTree jTree = field.getAnnotation(JTree.clreplaced);
    By selectLocator = findByToBy(jTree.select());
    avatar = new GetElementModule(selectLocator, this);
    treeLocators = new ArrayList<>();
    for (FindBy fBy : jTree.levels()) treeLocators.add(findByToBy(fBy));
}

19 View Complete Implementation : ComboBoxElement.java
Copyright GNU General Public License v3.0
Author : epam
public void setUp(By expandBy, By elementsByName) {
    if (expandBy != null)
        avatar.setByLocator(expandBy);
    dropdownManager = new DropdownManager<>(this, elementsByName);
}

19 View Complete Implementation : GetElementType.java
Copyright GNU General Public License v3.0
Author : epam
/**
 * Created by Roman_Iovlev on 9/28/2015.
 */
public clreplaced GetElementType {

    private By locator;

    private Object parent;

    public boolean hasLocator() {
        return locator != null;
    }

    public GetElementType() {
    }

    public GetElementType(By locator, Object parent) {
        this.locator = locator;
        this.parent = parent;
    }

    public <T extends BaseElement> T get(Clreplaced<T> clazz) {
        try {
            if (locator == null)
                return null;
            else {
                T result = clazz.newInstance();
                Element el = new Element(locator);
                el.setParent(parent);
                result.init(parent, new GetElementModule(locator, el));
                return result;
            }
        } catch (Exception ignore) {
            return null;
        }
    }
}

19 View Complete Implementation : BaseElement.java
Copyright GNU General Public License v3.0
Author : epam
public BaseElement setAvatar(By byLocator) {
    this.avatar = this.avatar.copy(byLocator);
    return this;
}

19 View Complete Implementation : WebDriverByUtils.java
Copyright GNU General Public License v3.0
Author : epam
public static By trimRoot(By by) {
    String byLocator = getByLocator(by).replace("*root*", " ").trim();
    return getByFunc(by).apply(byLocator);
}

19 View Complete Implementation : WebDriverByUtils.java
Copyright GNU General Public License v3.0
Author : epam
public static By correctXPaths(By byValue) {
    return byValue.toString().contains("By.xpath: //") ? getByFunc(byValue).apply(getByLocator(byValue).replaceFirst("/", "./")) : byValue;
}

19 View Complete Implementation : AngularCheckbox.java
Copyright GNU General Public License v3.0
Author : epam
/**
 * Created by Roman_Iovlev on 2/24/2017.
 */
public clreplaced AngularCheckbox extends CheckBox {

    public By isCheckedLocator;

    public AngularCheckbox(String name) {
        super(By.cssSelector("[name=" + name + "] .md-container"));
        isCheckedLocator = By.cssSelector("[name=" + name + "]");
    }

    @Override
    protected boolean isCheckedAction() {
        return $(isCheckedLocator).attr("aria-checked").equals("true");
    }
}

19 View Complete Implementation : BaseElement.java
Copyright GNU General Public License v3.0
Author : epam
public void setLocator(By locator) {
    avatar.setByLocator(locator);
}

19 View Complete Implementation : WebDriverByUtils.java
Copyright GNU General Public License v3.0
Author : epam
public static String getByName(By by) {
    Matcher m = Pattern.compile("By\\.(?<locator>.*):.*").matcher(by.toString());
    if (m.find())
        return m.group("locator");
    throw new RuntimeException("Can't get By name for: " + by);
}

19 View Complete Implementation : Element.java
Copyright GNU General Public License v3.0
Author : epam
public List<WebElement> getList(By locator) {
    return getWebElement().findElements(locator);
}

19 View Complete Implementation : BaseElement.java
Copyright GNU General Public License v3.0
Author : epam
@Override
public String printContext() {
    if (!(parent instanceof BaseElement))
        return "";
    BaseElement parentBaseElement = (BaseElement) parent;
    By locator = parentBaseElement.avatar.getByLocator();
    if (locator == null)
        return "";
    String parentContext = parentBaseElement.printContext();
    if (parentContext.equals(""))
        return locator.toString();
    return locator.toString() + "; " + parentContext;
}

19 View Complete Implementation : Cell.java
Copyright GNU General Public License v3.0
Author : epam
public WebElement get(By subLocator) {
    // TODO
    return null;
// return get().get(subLocator);
}

19 View Complete Implementation : WebDriverByUtils.java
Copyright GNU General Public License v3.0
Author : epam
public static By trimRoot(By by) {
    String byLocator = getByLocator(by).replace("*root*", " ").trim();
    return getByFunc(by).apply(byLocator);
}

19 View Complete Implementation : TableLine.java
Copyright GNU General Public License v3.0
Author : epam
private List<WebElement> getElementByTemplate(Object value) {
    By locator = fillByTemplate(lineTemplate != null ? lineTemplate : defaultTemplate, value);
    return where(table.getWebElement().findElements(locator), WebElement::isDisplayed);
}

19 View Complete Implementation : AppiumCascadeInit.java
Copyright GNU General Public License v3.0
Author : epam
protected IBaseElement getElementsRules(Field field, String driverName, Clreplaced<?> type, String fieldName) throws IllegalAccessException, InstantiationException {
    By newLocator = getNewLocator(field);
    BaseElement instance = null;
    if (isInterface(type, List.clreplaced)) {
        Clreplaced<?> elementClreplaced = (Clreplaced<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
        if (elementClreplaced.isInterface())
            elementClreplaced = getClreplacedFromInterface(type);
        if (elementClreplaced != null)
            instance = new Elements(newLocator, elementClreplaced);
    } else {
        if (type.isInterface())
            type = getClreplacedFromInterface(type);
        if (type != null) {
            instance = (BaseElement) type.newInstance();
            if (instance.getAvatar() != null && newLocator == null)
                instance.setAvatar(new GetElementModule(instance));
            else
                instance.setAvatar(new GetElementModule(newLocator, instance));
        }
    }
    if (instance == null)
        throw exception("Unknown interface: %s (%s). Add relation interface -> clreplaced in VIElement.InterfaceTypeMap", type, fieldName);
    instance.avatar.setDriverName(driverName);
    return instance;
}

19 View Complete Implementation : BaseElement.java
Copyright GNU General Public License v3.0
Author : epam
public BaseElement setAvatar(By byLocator, GetElementModule avatar) {
    this.avatar = avatar.copy(byLocator);
    return this;
}

19 View Complete Implementation : WebDriverByUtils.java
Copyright GNU General Public License v3.0
Author : epam
public static By fillByMsgTemplate(By by, Object... args) {
    String byLocator = getByLocator(by);
    try {
        byLocator = MessageFormat.format(byLocator, args);
    } catch (Exception ex) {
        throw new RuntimeException(getBadLocatorMsg(byLocator, args));
    }
    return getByFunc(by).apply(byLocator);
}

19 View Complete Implementation : Table.java
Copyright GNU General Public License v3.0
Author : epam
public ITable setUp(By root, By cell, By row, By column, By footer, int colStartIndex, int rowStartIndex) {
    setAvatar(root);
    cellLocatorTemplate = cell;
    rows.lineTemplate = row;
    columns.lineTemplate = column;
    footerLocator = footer;
    columns.startIndex = colStartIndex;
    rows.startIndex = rowStartIndex;
    return this;
}

19 View Complete Implementation : GetElementModule.java
Copyright GNU General Public License v3.0
Author : epam
public GetElementModule copy(By byLocator) {
    GetElementModule clone = new GetElementModule(byLocator, element);
    clone.localElementSearchCriteria = localElementSearchCriteria;
    clone.frameLocator = frameLocator;
    clone.driverName = driverName;
    clone.element = element;
    clone.webElement = webElement;
    clone.webElements = webElements;
    return clone;
}

19 View Complete Implementation : WebDriverByUtils.java
Copyright GNU General Public License v3.0
Author : epam
public static By fillByTemplate(By by, Object... args) {
    String byLocator = getByLocator(by);
    if (!byLocator.contains("%"))
        throw new RuntimeException(getBadLocatorMsg(byLocator, args));
    try {
        byLocator = format(byLocator, args);
    } catch (Exception ex) {
        throw new RuntimeException(getBadLocatorMsg(byLocator, args));
    }
    return getByFunc(by).apply(byLocator);
}

19 View Complete Implementation : Menu.java
Copyright GNU General Public License v3.0
Author : epam
public void setup(Field field) {
    if (!fieldHasAnnotation(field, JMenu.clreplaced, IMenu.clreplaced))
        return;
    JMenu jMenu = field.getAnnotation(JMenu.clreplaced);
    menuLevelsLocators = new ArrayList<>();
    menuLevelsLocators.add(findByToBy(jMenu.level1()));
    By level = findByToBy(jMenu.level2());
    if (level == null)
        return;
    menuLevelsLocators.add(level);
    level = findByToBy(jMenu.level3());
    if (level == null)
        return;
    menuLevelsLocators.add(level);
    level = findByToBy(jMenu.level4());
    if (level == null)
        return;
    menuLevelsLocators.add(level);
    level = findByToBy(jMenu.level5());
    if (level == null)
        return;
    menuLevelsLocators.add(level);
}

19 View Complete Implementation : Dropdown.java
Copyright GNU General Public License v3.0
Author : epam
public void setUp(By root, By value, By list, By expand, By elementByName) {
    if (root != null) {
        Element el = new Element(root);
        el.setParent(getParent());
        setParent(el);
    }
    if (value != null) {
        element = new GetElementType(value, this);
        if (expander == null)
            expander = element;
    }
    if (list != null)
        allLabels = new GetElementType(list, this);
    if (expand != null) {
        expander = new GetElementType(expand, this);
        if (element == null)
            element = expander;
    }
    if (elementByName != null)
        this.elementByName = new GetElementType(elementByName, this);
}

19 View Complete Implementation : WebDriverByUtils.java
Copyright GNU General Public License v3.0
Author : epam
public static By copyBy(By by) {
    String byLocator = getByLocator(by);
    return getByFunc(by).apply(byLocator);
}