package nl.hsac.fitnesse.fixture.util.selenium.by;

import org.openqa.selenium.By;

/**
 * Container for generic heuristics to find elements.
 */
public class ElementBy {
    public static By heuristic(String place) {
        return new Heuristic(place);
    }

    public static By exact(String place) {
        return new Exact(place);
    }

    public static By partial(String place) {
        return new Partial(place);
    }

    /**
     * Finds using heuristic.
     */
    public static class Heuristic extends AbstractHeuristicBy {
        public Heuristic(String place) {
            super(exact(place), partial(place));
        }
    }

    /**
     * Finds by exact link text.
     */
    public static class Exact extends AbstractHeuristicBy {
        public Exact(String place) {
            super(LabelBy.exact(place),
                    new CssBy("input[placeholder='%s']", place),
                    InputBy.exactValue(place),
                    new CssBy("textarea[placeholder='%s']", place),
                    new XPathBy(".//th/descendant-or-self::text()[normalized(.)='%s']/ancestor-or-self::th[1]/../td ", place),
                    new XPathBy(".//dt/descendant-or-self::text()[normalized(.)='%s']/ancestor-or-self::dt[1]/following-sibling::dd[1] ", place),
                    AriaLabelBy.exact(place),
                    new CssBy("[title='%s']", place));
        }
    }

    /**
     * Finds by partial link text.
     */
    public static class Partial extends AbstractHeuristicBy {
        public Partial(String place) {
            super(LabelBy.partial(place),
                    new CssBy("input[placeholder*='%s']", place),
                    InputBy.partialValue(place),
                    new CssBy("textarea[placeholder*='%s']", place),
                    new XPathBy(".//th/descendant-or-self::text()[contains(normalized(.), '%s')]/ancestor-or-self::th[1]/../td ", place),
                    new XPathBy(".//dt/descendant-or-self::text()[contains(normalized(.), '%s')]/ancestor-or-self::dt[1]/following-sibling::dd[1] ", place),
                    AriaLabelBy.partial(place),
                    new CssBy("[title*='%s']", place));
        }
    }
}

@@ -1153,33 +1153,32 @@
 elf::th%5B1%5D/../td
- 
 %22, place),%0D%0A    
@@ -1299,33 +1299,32 @@
 g-sibling::dd%5B1%5D
- 
 %22, place),%0D%0A    
@@ -1955,17 +1955,16 @@
 1%5D/../td
- 
 %22, place
@@ -2112,17 +2112,16 @@
 g::dd%5B1%5D
- 
 %22, place

Remove extra spaces