package com.sdl.selenium.web.table;

import com.sdl.selenium.web.SearchType;
import com.sdl.selenium.web.WebLocator;
import org.apache.log4j.Logger;

public class TableCell extends Cell {
    private static final Logger logger = Logger.getLogger(TableCell.class);

    public TableCell() {
        setRenderMillis(200);
        setClassName("TableCell");
        setTag("td");
    }

    public TableCell(WebLocator container) {
        this();
        setContainer(container);
    }

    public TableCell(WebLocator container, int columnIndex) {
        this(container);
        setPosition(columnIndex);
    }

    public TableCell(int columnIndex, String columnText, SearchType ...searchType) {
        this();
        setPosition(columnIndex);
        setText(columnText);
        setSearchTextType(searchType);
    }

    public TableCell(WebLocator container, int columnIndex, String columnText, SearchType ...searchType) {
        this(container, columnIndex);
        setText(columnText);
        setSearchTextType(searchType);
    }

    @Override
    protected String addPositionToPath(String itemPath) {
        if (hasPosition()) {
            itemPath = "//" + getTag() + "[" + getPosition() + "]" + ("".equals(getItemPathText()) ? "" : (getItemPathText() == null ? "" : "[" + getItemPathText() + "]"));
        }
        return itemPath;
    }

    @Override
    protected String getItemPathText() {
        String selector = super.getItemPathText();
        if (!"".equals(selector) && selector != null) {
            selector = selector + " or count(.//*[" + selector + "]) > 0";
        }
        return selector;
    }
}

@@ -1174,24 +1174,78 @@
 ition()) %7B%0D%0A
+            String itemPathText = getItemPathText();%0D%0A
             
@@ -1312,20 +1312,17 @@
 .equals(
-getI
+i
 temPathT
@@ -1324,18 +1324,16 @@
 PathText
-()
 ) ? %22%22 :
@@ -1334,20 +1334,17 @@
 ? %22%22 : (
-getI
+i
 temPathT
@@ -1346,18 +1346,16 @@
 PathText
-()
  == null
@@ -1368,20 +1368,17 @@
 : %22%5B%22 + 
-getI
+i
 temPathT
@@ -1380,18 +1380,16 @@
 PathText
-()
  + %22%5D%22))

improve addPositionToPath