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

com.slickqa.webdriver.finders.AbstractFindByParentBy Maven / Gradle / Ivy

There is a newer version: 1.0.1-37
Show newest version
package com.slickqa.webdriver.finders;

import java.util.ArrayList;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebElement;

/**
 * By implementing the abstract methods of this abstract class you can easily create a finder
 * which looks for the value of an attribute in a list of elements.
 *
 * @author jcorbett
 */
public abstract class AbstractFindByParentBy extends By
{
	public abstract boolean matches(WebElement e);

	public abstract List getParentBy();

	@Override
	public List findElements(SearchContext context)
	{
		ArrayList possible_elements = new ArrayList();
		for(By parentBy: getParentBy())
		{
			possible_elements.addAll(context.findElements(parentBy));
		}
		List retval = new ArrayList();
		for (WebElement possible : possible_elements)
		{
			if (matches(possible))
			{
				retval.add(possible);
			}
		}
		return retval;

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy