Class: Watir::JavaScripter

Inherits:
Object show all
Defined in:
lib/safariwatir/scripter.rb

Overview

:nodoc:

Direct Known Subclasses

FrameJavaScripter, TableJavaScripter

Instance Method Summary collapse

Instance Method Details

#find_cell(cell) ⇒ Object

Raises:

  • (RuntimeError)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/safariwatir/scripter.rb', line 42

def find_cell(cell)
  return %|getElementById('#{cell.what}')| if cell.how == :id
  raise RuntimeError, "Unable to use #{cell.how} to find TableCell" unless cell.row

  finder = 
  case cell.row.how
  when :id
    %|getElementById('#{cell.row.what}')|
  when :index
    case cell.row.table.how
    when :id
      %|getElementById('#{cell.row.table.what}').rows[#{cell.row.what-1}]|
    when :index
      %|getElementsByTagName('TABLE')[#{cell.row.table.what-1}].rows[#{cell.row.what-1}]|
    else
      raise MissingWayOfFindingObjectException, "Table element does not support #{cell.row.table.how}"
    end
  else
    raise MissingWayOfFindingObjectException, "TableRow element does not support #{cell.row.how}"
  end
  
  finder + %|.cells[#{cell.what-1}]|
end

#operate(locator, operation) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/safariwatir/scripter.rb', line 20

def operate(locator, operation)
%|#{locator}
if (element) {
  #{operation}
} else {
  return '#{ELEMENT_NOT_FOUND}';
}|
end

#wrap(script) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/safariwatir/scripter.rb', line 29

def wrap(script)
  # Needed because createEvent must be called on a document, and the JavaScripter sub-classes
  # do some transformations to lower-case "document" before we get here at runtime.
  script.gsub! "DOCUMENT", "document"
  
# Needed because I would like to blindly use return statements, but Safari 3 enforces
# the ECMAScript standard that return statements are only valid within functions.
%|#{JS_LIBRARY}
(function() {
  #{script}
})()|
end