1 /** 2 * Copyright (c) 2002-2015, JWebUnit team. 3 * 4 * This file is part of JWebUnit. 5 * 6 * JWebUnit is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * JWebUnit is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with JWebUnit. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 package net.sourceforge.jwebunit.api; 20 21 import java.util.List; 22 23 /** 24 * A wrapper around elements so we can access their properties directly, 25 * without requiring either direct access to the testing engine DOM, 26 * or implementing every permutation of assert test. 27 * 28 * @author jmwright 29 * 30 */ 31 public interface IElement { 32 33 /** 34 * Get the value of an attribute. 35 * 36 * @param name The attribute name 37 * @return The value of the attribute 38 */ 39 public String getAttribute(String name); 40 41 /** 42 * Get the element name, for example "input", "textarea", "select". 43 * 44 * @return The element name 45 */ 46 public String getName(); 47 48 /** 49 * Get the text content, if any, of this element. 50 * 51 * @return The text content, if any, of this element. 52 */ 53 public String getTextContent(); 54 55 /** 56 * Get the parent element, or {@code null} if none exists. 57 * 58 * @return The parent element or {@code null} 59 */ 60 public IElement getParent(); 61 62 /** 63 * Get direct child elements of this element. 64 * 65 * @return A list of child elements 66 */ 67 public List<IElement> getChildren(); 68 69 /** 70 * Get an element from this element by xpath. 71 * 72 * @param xpath The xpath to serach 73 * @return an IElement if found, or null 74 */ 75 public IElement getElement(String xpath); 76 77 /** 78 * Get all elements from this element by xpath. 79 * 80 * @param xpath The xpath to search 81 * @return A list of all matching elements 82 */ 83 public List<IElement> getElements(String xpath); 84 85 /** 86 * Set an attribute on this element, e.g. "checked" for HTML4 <select>s. 87 * 88 * @param string the attribute name 89 */ 90 public void setAttribute(String name); 91 92 /** 93 * Set an attribute on this element. 94 * 95 * @param string the attribute name 96 * @param value the new attribute value 97 */ 98 public void setAttribute(String name, String value); 99 100 /** 101 * Set the text content on this element. 102 * Note that if you are trying to set the value of an <input> input, you should use 103 * {@code setAttribute("value")} instead. 104 * This also sets the text content of a <textarea> element. 105 * 106 * @param value the new inner text content of this element 107 * @see #setAttribute(String, String) 108 */ 109 public void setTextContent(String value); 110 111 /** 112 * Two {@link IElement}s are equal if they 113 * refer to the same element in the current page. 114 * 115 * @param obj the object to compare 116 * @return <code>true</code> if the object is an {@link IElement}, and refers to the same 117 * element as this {@link IElement} 118 */ 119 public boolean equals(Object obj); 120 121 }