use of org.openqa.selenium.SearchContext in project selenium_java by sergueik.
the class TripAdvisorTest method findElements.
private List<WebElement> findElements(String selectorKind, String selectorValue, WebElement parent) {
SearchContext finder;
String parent_css_selector = null;
String parent_xpath = null;
List<WebElement> elements = null;
Hashtable<String, Boolean> selectorStrategies = new Hashtable<String, Boolean>();
selectorStrategies.put("css_selector", true);
selectorStrategies.put("xpath", true);
if (selectorKind == null || !selectorStrategies.containsKey(selectorKind) || !selectorStrategies.get(selectorKind)) {
return null;
}
if (parent != null) {
parent_css_selector = cssSelectorOfElement(parent);
parent_xpath = xpathOfElement(parent);
finder = parent;
} else {
finder = driver;
}
if (selectorKind == "css_selector") {
String extended_css_selector = String.format("%s %s", parent_css_selector, selectorValue);
try {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(extended_css_selector)));
} catch (RuntimeException timeoutException) {
return null;
}
elements = finder.findElements(By.cssSelector(selectorValue));
}
if (selectorKind == "xpath") {
String extended_xpath = String.format("%s/%s", parent_xpath, selectorValue);
try {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(extended_xpath)));
} catch (RuntimeException timeoutException) {
return null;
}
elements = finder.findElements(By.xpath(selectorValue));
}
return elements;
}
use of org.openqa.selenium.SearchContext in project selenium_java by sergueik.
the class AppTest method findElements.
private List<WebElement> findElements(String selectorKind, String selectorValue, WebElement parent) {
SearchContext finder;
String parent_css_selector = null;
String parent_xpath = null;
List<WebElement> elements = null;
Hashtable<String, Boolean> supportedSelectorStrategies = new Hashtable<String, Boolean>();
supportedSelectorStrategies.put("css_selector", true);
supportedSelectorStrategies.put("xpath", true);
if (selectorKind == null || !supportedSelectorStrategies.containsKey(selectorKind) || !supportedSelectorStrategies.get(selectorKind)) {
return null;
}
if (parent != null) {
parent_css_selector = cssSelectorOfElement(parent);
parent_xpath = xpathOfElement(parent);
finder = parent;
} else {
finder = driver;
}
if (selectorKind == "css_selector") {
String extended_css_selector = String.format("%s %s", parent_css_selector, selectorValue);
try {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(extended_css_selector)));
} catch (RuntimeException timeoutException) {
return null;
}
elements = finder.findElements(By.cssSelector(selectorValue));
}
if (selectorKind == "xpath") {
String extended_xpath = String.format("%s/%s", parent_xpath, selectorValue);
try {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(extended_xpath)));
} catch (RuntimeException timeoutException) {
return null;
}
elements = finder.findElements(By.xpath(selectorValue));
}
return elements;
}
use of org.openqa.selenium.SearchContext in project selenium_java by sergueik.
the class App method find_elements.
private static List<WebElement> find_elements(String selector_type, String selector_value, WebElement parent) {
int flexible_wait_interval = 5;
SearchContext finder;
long wait_polling_interval = 500;
String parent_css_selector = null;
String parent_xpath = null;
WebDriverWait wait = new WebDriverWait(driver, flexible_wait_interval);
wait.pollingEvery(wait_polling_interval, TimeUnit.MILLISECONDS);
List<WebElement> elements = null;
Hashtable<String, Boolean> supported_selectors = new Hashtable<String, Boolean>();
supported_selectors.put("css_selector", true);
supported_selectors.put("xpath", true);
if (selector_type == null || !supported_selectors.containsKey(selector_type) || !supported_selectors.get(selector_type)) {
return null;
}
if (parent != null) {
parent_css_selector = css_selector_of(parent);
parent_xpath = xpath_of(parent);
finder = parent;
} else {
finder = driver;
}
if (selector_type == "css_selector") {
String extended_css_selector = String.format("%s %s", parent_css_selector, selector_value);
try {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(extended_css_selector)));
} catch (RuntimeException timeoutException) {
return null;
}
elements = finder.findElements(By.cssSelector(selector_value));
}
if (selector_type == "xpath") {
String extended_xpath = String.format("%s/%s", parent_xpath, selector_value);
try {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(extended_xpath)));
} catch (RuntimeException timeoutException) {
return null;
}
elements = finder.findElements(By.xpath(selector_value));
}
return elements;
}
use of org.openqa.selenium.SearchContext in project java-client by appium.
the class ByChained method findElement.
@Override
public WebElement findElement(SearchContext context) {
AppiumFunction<SearchContext, WebElement> searchingFunction = null;
for (By by : bys) {
searchingFunction = Optional.ofNullable(searchingFunction != null ? searchingFunction.andThen(getSearchingFunction(by)) : null).orElse(getSearchingFunction(by));
}
FluentWait<SearchContext> waiting = new FluentWait<>(context);
try {
checkNotNull(searchingFunction);
return waiting.until(searchingFunction);
} catch (TimeoutException e) {
throw new NoSuchElementException("Cannot locate an element using " + toString());
}
}
use of org.openqa.selenium.SearchContext in project java-client by appium.
the class AppiumElementLocatorFactory method createLocator.
@Override
@Nullable
public CacheableLocator createLocator(AnnotatedElement annotatedElement) {
TimeOutDuration customDuration;
if (annotatedElement.isAnnotationPresent(WithTimeout.class)) {
WithTimeout withTimeout = annotatedElement.getAnnotation(WithTimeout.class);
customDuration = new TimeOutDuration(withTimeout.time(), withTimeout.unit());
} else {
customDuration = duration;
}
builder.setAnnotated(annotatedElement);
By byResult = builder.buildBy();
return ofNullable(byResult).map(by -> new AppiumElementLocator(searchContext, by, builder.isLookupCached(), customDuration)).orElse(null);
}
Aggregations