 
 
   @doc "Get an element's tag name"
-  @spec tag_name(String.t) :: String.t
-  def tag_name(element_id) do
+  @spec tag_name(element) :: String.t
+  def tag_name(element) do
+    element_id = get_element_id(element)
     session_id = Hound.get_current_session_id
     make_req(:get, "session/#{session_id}/element/#{element_id}/name")
   end
 
 
   @doc "Clear textarea or input element's value"
-  @spec clear_field(String.t) :: :ok
-  def clear_field(element_id) do
+  @spec clear_field(element) :: :ok
+  def clear_field(element) do
+    element_id = get_element_id(element)
     session_id = Hound.get_current_session_id
     make_req(:post, "session/#{session_id}/element/#{element_id}/clear")
   end
 
 
   @doc "Check if a checkbox or radio input group has any option selected"
-  @spec selected?(String.t) :: :true | :false
-  def selected?(element_id) do
+  @spec selected?(element) :: :true | :false
+  def selected?(element) do
+    element_id = get_element_id(element)
     session_id = Hound.get_current_session_id
     make_req(:get, "session/#{session_id}/element/#{element_id}/selected")
   end
 
 
   @doc "Check if an input field is enabled"
-  @spec enabled?(String.t) :: :true | :false
-  def enabled?(element_id) do
+  @spec enabled?(element) :: :true | :false
+  def enabled?(element) do
+    element_id = get_element_id(element)
     session_id = Hound.get_current_session_id
     make_req(:get, "session/#{session_id}/element/#{element_id}/enabled")
   end
 
 
   @doc "Get an element's attribute value"
-  @spec attribute_value(String.t, String.t) :: String.t | :nil
-  def attribute_value(element_id, attribute_name) do
+  @spec attribute_value(element, String.t) :: String.t | :nil
+  def attribute_value(element, attribute_name) do
+    element_id = get_element_id(element)
     session_id = Hound.get_current_session_id
     make_req(:get, "session/#{session_id}/element/#{element_id}/attribute/#{attribute_name}")
   end

defmodule Hound.JsonDriver.Element do
  import Hound.JsonDriver.Utils

  @doc "Get visible text of element"
  @spec visible_text(String.t) :: String.t
  def visible_text(element_id) do
    session_id = Hound.get_current_session_id
    result = make_req(:get, "session/#{session_id}/element/#{element_id}")
    cond do



  @doc "Check if an element is currently displayed"
  @spec displayed?(element) :: :true | :false
  def displayed?(element) do
    element_id = get_element_id(element)
    session_id = Hound.get_current_session_id
    make_req(:get, "session/#{session_id}/element/#{element_id}/displayed")
  end


  @doc "Get element's location on page"
  @spec element_location(element) :: tuple
  def element_location(element) do
    element_id = get_element_id(element)
    session_id = Hound.get_current_session_id
    make_req(:get, "session/#{session_id}/element/#{element_id}/location")
  end


  @doc "Get element size pixels"
  @spec element_size(element) :: tuple
  def element_size(element) do
    element_id = get_element_id(element)
    session_id = Hound.get_current_session_id
    make_req(:get, "session/#{session_id}/element/#{element_id}/size")
  end


  @doc "Get an element's computed CSS property"
  @spec css_property(element, String.t) :: String.t
  def css_property(element, property_name) do
    element_id = get_element_id(element)
    session_id = Hound.get_current_session_id
    make_req(:get, "session/#{session_id}/element/#{element_id}/css/#{property_name}")
  end


  @doc "Click on element"
  @spec click(element) :: :ok
  def click(element) do
    element_id = get_element_id(element)
    session_id = Hound.get_current_session_id
    make_req(:post, "session/#{session_id}/element/#{element_id}/click")
  end


  @doc "Submit form"
  @spec submit(element) :: :ok
  def submit(element) do
    element_id = get_element_id(element)
    session_id = Hound.get_current_session_id
    make_req(:post, "session/#{session_id}/element/#{element_id}/submit")
  end


  @doc false
  defp get_element_id(element) do
    if is_tuple(element) do
      {strategy, selector} = element
      Hound.JsonDriver.Page.find_element(strategy, selector)
    else
      element
    end
  end
end
