package com.frameworkium.core.ui.capture.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.frameworkium.core.ui.driver.Driver;
import org.openqa.selenium.WebElement;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Command {

    public String action;
    public String using;
    public String value;

    /**
     * Create Command object.
     */
    public Command(String action, String using, String value) {
        this.action = action;
        this.using = using;
        this.value = value;
    }

    /**
     * Create Command object.
     */
    public Command(String action, WebElement element) {
        this.action = action;

        // TODO: Improve this. Use hacky solution in LoggingListener?
        if (Driver.isNative()) {
            this.using = "n/a";
            this.value = "n/a";
        } else {
            if (!(element.getAttribute("id")).isEmpty()) {
                this.using = "id";
                this.value = element.getAttribute("id");
            } else if (!(element.getText()).isEmpty()) {
                this.using = "linkText";
                this.value = element.getText();
            } else if (!element.getTagName().isEmpty()) {
                this.using = "css";
                this.value = element.getTagName() + "."
                        + element.getAttribute("class").replace(" ", ".");
            } else {
                // must be something weird
                this.using = "n/a";
                this.value = "n/a";
            }
        }
    }
}

@@ -142,16 +142,61 @@
 Driver;%0A
+import org.apache.commons.lang3.StringUtils;%0A
 import o
@@ -375,54 +375,8 @@
 e;%0A%0A
-    /**%0A     * Create Command object.%0A     */%0A
     
@@ -532,54 +532,8 @@
  %7D%0A%0A
-    /**%0A     * Create Command object.%0A     */%0A
     
@@ -614,16 +614,113 @@
 action;%0A
+        setUsingAndValue(element);%0A    %7D%0A%0A    private void setUsingAndValue(WebElement element) %7B
 %0A       
@@ -908,25 +908,46 @@
         if (
-!
+StringUtils.isNotBlank
 (element.get
@@ -962,26 +962,16 @@
 e(%22id%22))
-.isEmpty()
 ) %7B%0A    

Tidy up Command