Class: WatirNokogiri::Document

Inherits:
Object
  • Object
show all
Includes:
Container
Defined in:
lib/watir-nokogiri/document.rb

Overview

The main class through which you control the html.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Container

#a, #abbr, #abbrs, #address, #addresses, #area, #areas, #article, #articles, #as, #aside, #asides, #audio, #audios, #b, #base, #bases, #bdi, #bdis, #bdo, #bdos, #blockquote, #blockquotes, #body, #bodys, #br, #brs, #bs, #button, #buttons, #canvas, #canvases, #caption, #captions, #checkbox, #checkboxes, #cite, #cites, #code, #codes, #col, #colgroup, #colgroups, #cols, #command, #commands, #data, #datalist, #datalists, #datas, #dd, #dds, #del, #dels, #details, #detailses, #dfn, #dfns, #dialog, #dialogs, #div, #divs, #dl, #dls, #dt, #dts, #element, #elements, #em, #embed, #embeds, #ems, #extract_selector, #field_set, #field_sets, #fieldset, #fieldsets, #figcaption, #figcaptions, #figure, #figures, #file_field, #file_fields, #font, #fonts, #footer, #footers, #form, #forms, #frame, #frames, #frameset, #framesets, #h1, #h1s, #h2, #h2s, #h3, #h3s, #h4, #h4s, #h5, #h5s, #h6, #h6s, #head, #header, #headers, #heads, #hgroup, #hgroups, #hidden, #hiddens, #hr, #hrs, #htmls, #i, #iframe, #iframes, #image, #images, #img, #imgs, #input, #inputs, #ins, #inses, #is, #kbd, #kbds, #keygen, #keygens, #label, #labels, #legend, #legends, #li, #link, #links, #lis, #map, #maps, #mark, #marks, #menu, #menus, #meta, #metas, #meter, #meters, #nav, #navs, #noscript, #noscripts, #object, #objects, #ol, #ols, #optgroup, #optgroups, #option, #options, #output, #outputs, #p, #param, #params, #pre, #pres, #progress, #progresses, #ps, #q, #qs, #radio, #radios, #rp, #rps, #rt, #rts, #rubies, #ruby, #s, #samp, #samps, #script, #scripts, #section, #sections, #select, #select_list, #select_lists, #selects, #small, #smalls, #source, #sources, #span, #spans, #ss, #strong, #strongs, #style, #styles, #sub, #subs, #summaries, #summary, #sup, #sups, #table, #tables, #tbody, #tbodys, #td, #tds, #text_field, #text_fields, #textarea, #textareas, #tfoot, #tfoots, #th, #thead, #theads, #ths, #time, #times, #titles, #tr, #track, #tracks, #trs, #u, #ul, #uls, #us, #var, #vars, #video, #videos, #wbr, #wbrs

Constructor Details

#initialize(html = '') ⇒ Document

Creates a WatirNokogiri::HTML instance.



27
28
29
# File 'lib/watir-nokogiri/document.rb', line 27

def initialize(html = '')
  @driver = Nokogiri::HTML.parse(html)
end

Instance Attribute Details

#driverObject (readonly) Also known as: nokogiri

Returns the value of attribute driver.



11
12
13
# File 'lib/watir-nokogiri/document.rb', line 11

def driver
  @driver
end

Class Method Details

.start(file_path) ⇒ Object



15
16
17
18
19
20
# File 'lib/watir-nokogiri/document.rb', line 15

def start(file_path)
  b = new()
  b.goto file_path

  b
end

Instance Method Details

#add_checker(checker = nil, &block) ⇒ Object

Raises:

  • (NotImplementedError)


135
136
137
# File 'lib/watir-nokogiri/document.rb', line 135

def add_checker(checker = nil, &block)
  raise NotImplementedError, "not currently supported by WatirNokogiri"
end

#alertObject

Raises:

  • (NotImplementedError)


103
104
105
# File 'lib/watir-nokogiri/document.rb', line 103

def alert
  raise NotImplementedError, "not currently supported by WatirNokogiri"
end

#assert_existsObject



158
159
160
# File 'lib/watir-nokogiri/document.rb', line 158

def assert_exists
    true
end

#backObject

Raises:

  • (NotImplementedError)


52
53
54
# File 'lib/watir-nokogiri/document.rb', line 52

def back
  raise NotImplementedError, "not currently supported by WatirNokogiri"
end

#closeObject Also known as: quit



69
70
71
# File 'lib/watir-nokogiri/document.rb', line 69

def close
  @driver = nil
end

#cookiesObject

Raises:

  • (NotImplementedError)


74
75
76
# File 'lib/watir-nokogiri/document.rb', line 74

def cookies
  raise NotImplementedError, "not currently supported by WatirNokogiri"
end

#disable_checker(checker) ⇒ Object

Raises:

  • (NotImplementedError)


139
140
141
# File 'lib/watir-nokogiri/document.rb', line 139

def disable_checker(checker)
  raise NotImplementedError, "not currently supported by WatirNokogiri"
end

#documentObject



166
167
168
# File 'lib/watir-nokogiri/document.rb', line 166

def document
  self
end

#execute_script(script, *args) ⇒ Object

Raises:

  • (NotImplementedError)


123
124
125
# File 'lib/watir-nokogiri/document.rb', line 123

def execute_script(script, *args)
  raise NotImplementedError, "not currently supported by WatirNokogiri"
end

#exist?Boolean Also known as: exists?

Returns true if html has been supplied and false otherwise.

Returns:

  • (Boolean)


153
154
155
# File 'lib/watir-nokogiri/document.rb', line 153

def exist?
  !@driver.nil?
end

#forwardObject

Raises:

  • (NotImplementedError)


56
57
58
# File 'lib/watir-nokogiri/document.rb', line 56

def forward
  raise NotImplementedError, "not currently supported by WatirNokogiri"
end

#goto(file_path) ⇒ String

Reads the given file as HTML.

Examples:

browser.goto "www.google.com"

Parameters:

  • uri (String)

    The url.

Returns:

  • (String)

    The url you end up at.



47
48
49
50
# File 'lib/watir-nokogiri/document.rb', line 47

def goto(file_path)
  html = File.read(file_path)
  @driver = Nokogiri::HTML.parse(html)
end

#htmlString

Returns HTML code of current page.

Returns:

  • (String)


98
99
100
101
# File 'lib/watir-nokogiri/document.rb', line 98

def html
  # use body.html instead?
  @driver.at_css('html').to_html
end

#inspectObject



31
32
33
34
35
# File 'lib/watir-nokogiri/document.rb', line 31

def inspect
  '#<%s:0x%x>' % [self.class, hash*2]
rescue
  '#<%s:0x%x closed=%s>' % [self.class, hash*2, exist?.to_s]
end

#nameObject



78
79
80
# File 'lib/watir-nokogiri/document.rb', line 78

def name
  :nokogiri
end

#ready_stateObject

Raises:

  • (NotImplementedError)


115
116
117
# File 'lib/watir-nokogiri/document.rb', line 115

def ready_state
  raise NotImplementedError, "not currently supported by WatirNokogiri"
end

#refreshObject

Raises:

  • (NotImplementedError)


107
108
109
# File 'lib/watir-nokogiri/document.rb', line 107

def refresh
  raise NotImplementedError, "not currently supported by WatirNokogiri"
end

#reset!Object



162
163
164
# File 'lib/watir-nokogiri/document.rb', line 162

def reset!
  # no-op
end

#run_checkersObject

Raises:

  • (NotImplementedError)


143
144
145
# File 'lib/watir-nokogiri/document.rb', line 143

def run_checkers
  raise NotImplementedError, "not currently supported by WatirNokogiri"
end

#screenshotObject



131
132
133
# File 'lib/watir-nokogiri/document.rb', line 131

def screenshot
  Screenshot.new driver
end

#send_keys(*args) ⇒ Object

Raises:

  • (NotImplementedError)


127
128
129
# File 'lib/watir-nokogiri/document.rb', line 127

def send_keys(*args)
  raise NotImplementedError, "not currently supported by WatirNokogiri"
end

#statusObject

Raises:

  • (NotImplementedError)


119
120
121
# File 'lib/watir-nokogiri/document.rb', line 119

def status
  raise NotImplementedError, "not currently supported by WatirNokogiri"
end

#textString

Returns text of page body.

Returns:

  • (String)


88
89
90
# File 'lib/watir-nokogiri/document.rb', line 88

def text
  @driver.at_css('body').text
end

#titleObject



65
66
67
# File 'lib/watir-nokogiri/document.rb', line 65

def title
  @driver.title
end

#urlObject

Raises:

  • (NotImplementedError)


60
61
62
63
# File 'lib/watir-nokogiri/document.rb', line 60

def url
  assert_exists
  raise NotImplementedError, "not currently supported by WatirNokogiri"
end

#wait(timeout = 5) ⇒ Object

Raises:

  • (NotImplementedError)


111
112
113
# File 'lib/watir-nokogiri/document.rb', line 111

def wait(timeout = 5)
  raise NotImplementedError, "not currently supported by WatirNokogiri"
end