ElementProperties { public static ElementProperty hasText(String txt) { return new ElementProperty() { @Override public String toXpath() { return XpathUtils.textEquals(txt); } public String toString() { return "has the text \"" + txt + "\""; } }; } private  ElementProperties(); static ElementPropertyWithNumericalBoundaries hasNChildren(Integer n); static ElementProperty isNthFromLastSibling(Integer reverseIndex); static ElementProperty isNthSibling(Integer index); static ElementProperty withIndexInRange(int first, int last); static ElementProperty hasRawXpathProperty(String rawXpathProps, String rawExplanation); static ElementProperty hasText(String txt); static ElementProperty hasCaseSensitiveText(String txt); static ElementProperty hasTextStartingWith(String txt); static ElementProperty hasTextEndingWith(String txt); static ElementProperty hasId(String id); static ElementProperty hasName(String name); static ElementProperty hasSource(String src); static ElementProperty hasRole(String role); static ElementProperty hasRef(String ref); static ElementProperty hasAttribute(String attribute, String value); static ElementProperty hasAnyOfClasses(String... cssClasses); static ElementProperty hasClasses(String... cssClasses); static ElementProperty hasClassContaining(String classSubString); static ElementProperty hasNonOfTheClasses(String... cssClasses); static ElementProperty isWithIndex(Integer index); static ElementProperty hasTextContaining(String txt); static ElementProperty hasCaseSensitiveTextContaining(String txt); static ElementProperty hasClass(String className); static ElementProperty hasAggregatedTextEqualTo(String txt); static ElementProperty hasAggregatedCaseSensitiveTextEqualTo(String txt); static ElementProperty hasAggregatedTextStartingWith(String txt); static ElementProperty hasAggregatedTextEndingWith(String txt); static ElementProperty hasAggregatedTextContaining(String txt); static ElementProperty hasAggregatedCaseSensitiveTextContaining(String txt); static ElementProperty isChildOf(Path path); static ElementProperty hasParent(Path path); static ElementProperty isParentOf(Path... paths); static ElementProperty hasChild(Path... paths); static ElementProperty contains(Path... paths); static ElementProperty isAncestorOf(Path... paths); static ElementProperty hasDescendant(Path... paths); static ElementProperty hasAncesctor(Path path); static ElementProperty isDescendantOf(Path path); static ElementProperty isInside(Path path); static ElementProperty isContainedIn(Path path); static ElementProperty isAfter(Path... paths); static ElementProperty isAfter(NPath nPath); static ElementProperty isBefore(Path... paths); static ElementProperty isBefore(NPath nPath); static ElementProperty isSiblingOf(Path... paths); static ElementProperty isAfterSibling(Path... paths); static ElementProperty isAfterSibling(NPath nPath); static ElementProperty isBeforeSibling(Path... paths); static ElementProperty isBeforeSibling(NPath nPath); static ElementProperty not(ElementProperty prop); static final ElementProperty isLastSibling; static final ElementProperty isDisabled; static final ElementProperty isEnabled; static final ElementProperty isChecked; static final ElementProperty isSelected; static final ElementProperty hasNoChildren; static final ElementProperty hasChildren; static final ElementProperty isOnlyChild; static ElementProperty isHidden; static ElementProperty hasSomeText; }
@Test public void hasTextTest() { Path el = div.that(hasText("abc")); String xpath = el.getXPath().get(); NodeList nodes = findAllByXpath("<div>abcd</div><div>ABC</div><span>abc</span>", el); assertThat(nodes.getLength(), is(1)); assertThat(getText(nodes.item(0)), equalTo("ABC")); assertThat(getElementName(nodes.item(0)), equalTo("div")); assertThat(el.toString(), is(equalTo("div, that has the text \"abc\""))); }
@Test public void hasTextWithSingleQuoteTest() { Path el = div.that(hasText("I'm here")); String xpath = el.getXPath().get(); NodeList nodes = findAllByXpath("<div>abcd</div><div>I'm here</div><span>abc</span>", el); assertThat(nodes.getLength(), is(1)); assertThat(getText(nodes.item(0)), equalTo("I'm here")); assertThat(getElementName(nodes.item(0)), equalTo("div")); assertThat(el.toString(), is(equalTo("div, that has the text \"I'm here\""))); }