Package com.crawljax.core.configuration
Class CrawlElement
- java.lang.Object
-
- com.crawljax.core.configuration.CrawlElement
-
public final class CrawlElement extends Object
Represents the HTML elements which should be crawled. It represents all the HTML elements in the DOM that match the specified tag name. 1) <a class="foo" .. 2) <div... 3) <a href= "http:// CrawlElement exampleCrawlElement = new CrawlElement("a") represents the elements 1 and 3 You can refine the set of elements a CrawlElement represents by specifying attributes and XPath conditions For example, you can refine exampleCrawlElement to represent only element 1 using exampleCrawlElement.withAttribute("class", "foo");NOTE: In general CrawlElement is not designed to be instantiated directly. CrawlElement should be used as follows:
CrawljaxConfiguration crawler = new CrawljaxConfiguration(); crawler.click("a"); crawler.click("div").withAttribute("class", "clickable"); crawler.dontClick("a").withText("id", "logout"); crawler.dontClick("a").underXpath("//DIV[@id='header']");
-
-
Field Summary
Fields Modifier and Type Field Description static StringCLICKABLE_ELEMENT_TAGprivate List<Condition>conditionsprivate Eventable.EventTypeeventTypeprivate Stringidprivate List<FormInput>inputFieldIdsprivate StringtagNameprivate StringunderXpath
-
Constructor Summary
Constructors Modifier Constructor Description protectedCrawlElement(Eventable.EventType eventType, String tagName)To create a CrawlElement representing an HTML element <a>MyLink</a> the tag name would be "a".
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddInputFieldIds(List<FormInput> formInputs)protected StringescapeApostrophes(String text)Returns a string to resolve apostrophe issue in xpathprotected com.google.common.collect.ImmutableList<Condition>getConditions()EventableConditiongetEventableCondition()Eventable.EventTypegetEventType()StringgetId()protected com.google.common.collect.ImmutableList<FormInput>getInputFieldIds()StringgetTagName()StringgetWithXpathExpression()protected voidsetConditions(Condition... conditions)Sets the conditions.StringtoString()CrawlElementunderXPath(String xpathExpression)Restrict CrawlElement to include only HTML elements which are under HTML element X which identified by the xpath expression xpathExpression When xpathExpression returns no HTML elements this CrawlElement is not considered under element X.CrawlElementwhen(Condition... conditions)Crawljax will crawl the HTML elements while crawling if and only if all the specified conditions are satisfied.CrawlElementwithAttribute(String attributeName, String value)Restrict CrawlElement to include only HTML elements with the specified attribute.CrawlElementwithText(String text)Restrict CrawlElement to include only HTML elements which have the specified text For example 1) <a>Foo</a> 2) <a>Bar</a> 3) <a>Example 3a</a> withText("Foo") will include element 1 withText("Example %") will include elements3 Text can support wild-card characters.
-
-
-
Field Detail
-
CLICKABLE_ELEMENT_TAG
public static final String CLICKABLE_ELEMENT_TAG
- See Also:
- Constant Field Values
-
tagName
private final String tagName
-
id
private final String id
-
eventType
private final Eventable.EventType eventType
-
underXpath
private String underXpath
-
-
Constructor Detail
-
CrawlElement
protected CrawlElement(Eventable.EventType eventType, String tagName)
To create a CrawlElement representing an HTML element <a>MyLink</a> the tag name would be "a".- Parameters:
eventType- the event type for this crawl element.
-
-
Method Detail
-
when
public CrawlElement when(Condition... conditions)
Crawljax will crawl the HTML elements while crawling if and only if all the specified conditions are satisfied. IMPORTANT: only works with click()!!! For example: when(onContactPageCondition) will only click the HTML element if it is on the contact page- Parameters:
conditions- the condition to be met.- Returns:
- this
-
withAttribute
public CrawlElement withAttribute(String attributeName, String value)
Restrict CrawlElement to include only HTML elements with the specified attribute. For example <div class="foo">... <div class="bar">.. </div> </div> withAttribute("class", "foo") Would restrict this CrawlElement to only include the div with class="foo"... AttributeName and value strings can support wild-card characters. Use % in to represent a wild-card string. e.g (% is the regex .*) When withAttribute() is called multiple times the CrawlElement will match only those HTML elements that have all the specified attributes.- Parameters:
attributeName- the name of the attributevalue- the value of the attribute- Returns:
- this CrawlElement
-
underXPath
public CrawlElement underXPath(String xpathExpression)
Restrict CrawlElement to include only HTML elements which are under HTML element X which identified by the xpath expression xpathExpression When xpathExpression returns no HTML elements this CrawlElement is not considered under element X. Element X is included when it matches the other restrictions of this CrawlElement For example: <HTML> <BODY> <DIV id="foo"> <SPAN id="bar"> <A...></A> </SPAN> </DIV> .. //DIV[@id='foo'] includes the div, span and a elements //SPAN[@id='foo'] includes the span and a elements //DIV[@class='link'] will not include any elements IMPORTANT: In the xpath expression write elements in uppercase and attributes in lowercase- Parameters:
xpathExpression- the xpath expression where the element should under- Returns:
- This CrawlElement
-
withText
public CrawlElement withText(String text)
Restrict CrawlElement to include only HTML elements which have the specified text For example 1) <a>Foo</a> 2) <a>Bar</a> 3) <a>Example 3a</a> withText("Foo") will include element 1 withText("Example %") will include elements3 Text can support wild-card characters. Use % in to represent a wild-card string. e.g (% is the regex .*)- Parameters:
text- Text that should be inside the element.- Returns:
- CrawlElement with text
-
getEventableCondition
public EventableCondition getEventableCondition()
- Returns:
- the EventableCondition belonging to this CrawlElement
-
getId
public String getId()
- Returns:
- the id
-
getTagName
public String getTagName()
- Returns:
- The tag name.
-
getWithXpathExpression
public String getWithXpathExpression()
- Returns:
- the withXpathExpression
-
getConditions
protected com.google.common.collect.ImmutableList<Condition> getConditions()
- Returns:
- the conditions
-
setConditions
protected void setConditions(Condition... conditions)
Sets the conditions.- Parameters:
conditions- The conditions
-
getInputFieldIds
protected com.google.common.collect.ImmutableList<FormInput> getInputFieldIds()
- Returns:
- the inputFieldIds
-
addInputFieldIds
protected void addInputFieldIds(List<FormInput> formInputs)
- Parameters:
formInputs- Sets the list of input fields.
-
getEventType
public Eventable.EventType getEventType()
- Returns:
- the eventType
-
-