Skip to content

Instantly share code, notes, and snippets.

@handakumbura
Last active December 19, 2022 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save handakumbura/86e61e27a68b278154728c1387270de0 to your computer and use it in GitHub Desktop.
Save handakumbura/86e61e27a68b278154728c1387270de0 to your computer and use it in GitHub Desktop.
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