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

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

There is a newer version: 2.3.1
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.ArrayList;
import java.util.List;

/**
 * 

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

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

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

* * * @author Nir Gallner * @since 0.1 * * @see org.openqa.selenium.support.pagefactory.ByAll * @see AllBy * @see ElementBy * @see InputBy * @see NotBy * @see TdBy */ public class AnyBy extends By{ private final By[] bys; public AnyBy(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 By any(By... bys) { return new AnyBy(bys); } @Override public List findElements(SearchContext context){ List elements = new ArrayList<>(); for (By by : bys) { // Add all the elements we find elements.addAll(context.findElements(by)); } return elements; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy