             sbjBinding = 'subject.' + binding
             # Make the field element search selector.
             selector = By.binding(sbjBinding)
-            selectText(selector)
-          
+            findText(selector)
+
         addTextField(prop, binding) for prop, binding of bindings
 
       # Find the table.
       #
       # Note: A better solution is to perform the field selects below
-      # against the table panel rather than the page. However,
+      # against the table rather than the page. However,
       # panel.findElement('qi-demographics-table')
       # results in an error, since the untyped panel object has most, but
       # not all, of the WebElement function properties. In particular, it

            ethnicity: 'ethnicity'

      addComponentTable = (prop, selector, bindings) ->
        panel[prop] = -> selectTableWithBindings(selector, bindings)

      for prop, spec of componentTables
        addComponentTable(prop, spec.selector, spec.bindings)

    # Find the clinical profile panel.
    @select('.qi-clinical-profile').then (panel) =>
      if panel?
        # Add the component table functions.
        addComponentTables(panel)
        # Apply the function to the panel.
        fn(panel) if fn?
      panel



Page = require './helpers/page'

class SubjectDetailPage extends Page
  # @returns a promise which resolves to the image profile button
  #   ElementFinder
  imageProfileFormatButton: ->
    @find('#modeling-format-btn')

  # Finds the modeling table WebElements.
  # See profileTables.
  #
  # @returns the modeling tables promise
  modelingTables: ->
    @findTables('.qi-modeling-table')

  # @returns the modeling charts promise
  modelingCharts: ->
     @findAll('.qi-modeling-chart')

  # @returns the date line chart promise
  dateLine: ->
    @find('//qi-visit-dateline//nvd3-line-chart')

  # @returns the clinical profile panel promise
  clinicalProfile: ->
    # @param selector the selection criterion
    # @param bindings the table field {property: binding} bindings
    # @returns the target table augmented with the component table
    #   access functions, or null if the table was not found
    findTableWithBindings = (selector, bindings) =>
      # Gets the given WebElement text.
      text = (elt) -> elt.getText() if elt

      # Searches for a WebElement and resolves to its text.
      findText = (selector) => @find(selector).then(text)

      # @param table the target table
      # @param bindings the table field bindings
