Last active
December 19, 2022 02:54
-
-
Save handakumbura/86e61e27a68b278154728c1387270de0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dumiduh; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.SearchContext; | |
import org.openqa.selenium.WebElement; | |
import java.util.List; | |
public class CustomBy extends By { | |
private String searchTerm; | |
private final String XPATH = "//*[contains(text(),'%s')]"; | |
public static By containsText(String searchTerm) { | |
return new CustomBy(searchTerm); | |
} | |
private CustomBy(String value) { | |
this.searchTerm = value; | |
} | |
@Override | |
public List<WebElement> findElements(SearchContext context) { | |
return context.findElements(By.xpath(String.format(XPATH, searchTerm))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment