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

co.verisoft.fw.utils.locators.AllBy Maven / Gradle / Ivy

There is a newer version: 2.3.9
Show newest version
package co.verisoft.fw.utils.locators;
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.openqa.selenium.By;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebElement;

import java.util.List;

/**
 * 

* Find elements which comply to ALL the specified By objects.
* This mechanism used to locate elements within a document using a series of * lookups. This class will find all DOM elements that matches any of the * locators in sequence. For example:

* {@code List myList = driver.findElements(AllBy.all(By.xpath("path1"),By.xpath("path2"));}

* will find all elements that match xpath "path1" AND xpath "path2" and return a * {@link List} of {@link WebElement}. *

* * * @author Nir Gallner * @since 0.1 * * @see org.openqa.selenium.support.pagefactory.ByAll * @see AnyBy * @see ElementBy * @see InputBy * @see NotBy * @see TdBy */ public class AllBy extends By { private final By[] bys; private AllBy(By... bys) { this.bys = bys; } /** * * @param bys list of {@link By} objects to be used when {@link #findElements(SearchContext context) findElements} is called.} * @return {@link By } object with all the locators in it */ public static AllBy all(By... bys) { return new AllBy(bys); } @Override public List findElements(SearchContext context) { List elements = null; for (By by : bys) { List newElements = context.findElements(by); // If it is a new set if (null == elements) { elements = newElements; } else { elements.retainAll(newElements); } } return elements; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy