All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.automationrockstars.gir.mobile.ByVisibleTextAndroid Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright (c) 2015, 2016 Automation RockStars Ltd.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Apache License v2.0
 * which accompanies this distribution, and is available at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Contributors:
 *     Automation RockStars - initial API and implementation
 *******************************************************************************/
package com.automationrockstars.gir.mobile;

import com.google.common.collect.Lists;
import org.openqa.selenium.By;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebElement;

import java.util.List;

public class ByVisibleTextAndroid extends ByVisibleText {


    public ByVisibleTextAndroid(String... filter) {
        super(filter);
    }

    public List findElements(final SearchContext context, final List lines) {
        List result = Lists.newArrayList();
        for (String line : lines) {
            WebElement part;
            if (line.contains("content-desc") && PageUtils.getValueFromLine("content-desc", line).length() > 0) {
                part = By.name(PageUtils.getValueFromLine("content-desc", line)).findElement(context);
            } else {
                String className = line.replaceAll("^.*<", "").replaceAll("\\ .*", "");
                String instance = PageUtils.getValueFromLine("instance", line);
                part = By.xpath(String.format("//%s", className)).findElements(context).get(Integer.valueOf(instance));
            }
            result.add(part);
        }
        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy