ElementFinder implements Finder { public static String exitCondition(String findTag) { int pos = findTag.indexOf('}'); if (pos == -1) { return "e.tagName == '" + findTag.toUpperCase() + "'"; } int caretPos = findTag.indexOf('^'); boolean contains = caretPos != -1 && caretPos < pos; if (!contains) { caretPos = 0; } String tagName = StringUtils.trimToNull(findTag.substring(caretPos + 1, pos)); String suffix = tagName == null ? "" : " && e.tagName == '" + tagName.toUpperCase() + "'"; String findText = findTag.substring(pos + 1); if (contains) { return "e.textContent.trim().includes('" + findText + "')" + suffix; } else { return "e.textContent.trim() == '" + findText + "'" + suffix; } } ElementFinder(Driver driver, String fromLocator, Type type); static String exitCondition(String findTag); @Override Element find(); @Override Element find(String tag); @Override Element clear(); @Override Element input(String value); @Override Element select(String value); @Override Element select(int index); @Override Element click(); @Override Element highlight(); @Override Element retry(); @Override Element retry(int count); @Override Element retry(Integer count, Integer interval);  }
@Test public void testToJson() { String condition = ElementFinder.exitCondition("{^a}Foo"); assertEquals("e.textContent.trim().includes('Foo') && e.tagName == 'A'", condition); }