package com.crawljax.condition;


import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

import com.crawljax.browser.EmbeddedBrowser;
import com.crawljax.util.Helper;

/**
 * A condition which returns true if the XPath expression returns zero or more elements. NOTE:
 * element names must be in upper case and attributes in lower case.
 * 
 * @author dannyroest@gmail.com (Danny Roest)
 * @version $Id$
 */
public class XPathCondition extends AbstractCondition {

	private final String expression;

	/**
	 * Construct xpath condition.
	 * 
	 * @param expression
	 *            The actual xpath expression.
	 */
	public XPathCondition(String expression) {
		this.expression = expression;
	}

	@Override
	public boolean check(EmbeddedBrowser browser) {
		return checkXPathExpression(browser);
	}

	private boolean checkXPathExpression(EmbeddedBrowser browser) {
		try {
			Document document = Helper.getDocument(browser.getDom());
			NodeList nodeList = Helper.getElementsByXpath(document, expression);
			this.setAffectedNodes(nodeList);
			return nodeList.getLength() > 0;
		} catch (Exception e) {
			throw new RuntimeException("Error with " + this.getClass().getSimpleName() + ": "
			        + expression + "\n" + e.toString());
		}
	}

}

@@ -28,18 +28,16 @@
 ion;%0D%0A%0D%0A
-%0D%0A
 import o
@@ -247,12 +247,11 @@
 rns 
-zero
+one
  or 

Fix comment/logic error.