Class: Zenrows::JsInstructions
- Inherits:
-
Object
- Object
- Zenrows::JsInstructions
- Defined in:
- lib/zenrows/js_instructions.rb
Overview
DSL for building JavaScript instructions
JavaScript instructions enable dynamic interaction with web pages by automating user actions like clicking, filling forms, scrolling, and executing custom JavaScript.
Instance Attribute Summary collapse
-
#instructions ⇒ Array<Hash>
readonly
List of instructions.
Class Method Summary collapse
-
.build {|JsInstructions| ... } ⇒ JsInstructions
Build instructions using DSL block.
Instance Method Summary collapse
-
#check(selector) ⇒ self
Check a checkbox.
-
#click(selector) ⇒ self
Click an element.
-
#empty? ⇒ Boolean
Check if there are any instructions.
-
#evaluate(code) ⇒ self
Execute custom JavaScript.
-
#fill(selector, value) ⇒ self
Fill an input field.
-
#frame_click(iframe_selector, element_selector) ⇒ self
Click element inside iframe.
-
#frame_evaluate(iframe_name, code) ⇒ self
Execute JavaScript inside iframe.
-
#frame_fill(iframe_selector, input_selector, value) ⇒ self
Fill input inside iframe.
-
#frame_wait_for(iframe_selector, element_selector) ⇒ self
Wait for element inside iframe.
-
#initialize ⇒ JsInstructions
constructor
A new instance of JsInstructions.
-
#scroll_to(position) ⇒ self
Scroll to position.
-
#scroll_x(pixels) ⇒ self
Scroll horizontally.
-
#scroll_y(pixels) ⇒ self
Scroll vertically.
-
#select_option(selector, value) ⇒ self
Select an option from dropdown.
-
#size ⇒ Integer
Number of instructions.
-
#to_a ⇒ Array<Hash>
Convert to array.
-
#to_json(*_args) ⇒ String
Convert to JSON string for API.
-
#uncheck(selector) ⇒ self
Uncheck a checkbox.
-
#wait(duration) ⇒ self
Wait for a duration in milliseconds.
-
#wait_event(event) ⇒ self
Wait for a browser event.
-
#wait_for(selector) ⇒ self
Wait for an element to appear.
Constructor Details
#initialize ⇒ JsInstructions
Returns a new instance of JsInstructions.
35 36 37 |
# File 'lib/zenrows/js_instructions.rb', line 35 def initialize @instructions = [] end |
Instance Attribute Details
#instructions ⇒ Array<Hash> (readonly)
Returns List of instructions.
33 34 35 |
# File 'lib/zenrows/js_instructions.rb', line 33 def instructions @instructions end |
Class Method Details
.build {|JsInstructions| ... } ⇒ JsInstructions
Build instructions using DSL block
49 50 51 52 53 |
# File 'lib/zenrows/js_instructions.rb', line 49 def self.build(&block) builder = new builder.instance_eval(&block) if block builder end |
Instance Method Details
#check(selector) ⇒ self
Check a checkbox
123 124 125 126 |
# File 'lib/zenrows/js_instructions.rb', line 123 def check(selector) @instructions << {check: selector} self end |
#click(selector) ⇒ self
Click an element
63 64 65 66 |
# File 'lib/zenrows/js_instructions.rb', line 63 def click(selector) @instructions << {click: selector} self end |
#empty? ⇒ Boolean
Check if there are any instructions
256 257 258 |
# File 'lib/zenrows/js_instructions.rb', line 256 def empty? @instructions.empty? end |
#evaluate(code) ⇒ self
Execute custom JavaScript
193 194 195 196 |
# File 'lib/zenrows/js_instructions.rb', line 193 def evaluate(code) @instructions << {evaluate: code} self end |
#fill(selector, value) ⇒ self
Fill an input field
114 115 116 117 |
# File 'lib/zenrows/js_instructions.rb', line 114 def fill(selector, value) @instructions << {fill: [selector, value]} self end |
#frame_click(iframe_selector, element_selector) ⇒ self
Click element inside iframe
203 204 205 206 |
# File 'lib/zenrows/js_instructions.rb', line 203 def frame_click(iframe_selector, element_selector) @instructions << {frame_click: [iframe_selector, element_selector]} self end |
#frame_evaluate(iframe_name, code) ⇒ self
Execute JavaScript inside iframe
234 235 236 237 |
# File 'lib/zenrows/js_instructions.rb', line 234 def frame_evaluate(iframe_name, code) @instructions << {frame_evaluate: [iframe_name, code]} self end |
#frame_fill(iframe_selector, input_selector, value) ⇒ self
Fill input inside iframe
224 225 226 227 |
# File 'lib/zenrows/js_instructions.rb', line 224 def frame_fill(iframe_selector, input_selector, value) @instructions << {frame_fill: [iframe_selector, input_selector, value]} self end |
#frame_wait_for(iframe_selector, element_selector) ⇒ self
Wait for element inside iframe
213 214 215 216 |
# File 'lib/zenrows/js_instructions.rb', line 213 def frame_wait_for(iframe_selector, element_selector) @instructions << {frame_wait_for: [iframe_selector, element_selector]} self end |
#scroll_to(position) ⇒ self
Scroll to position
180 181 182 183 |
# File 'lib/zenrows/js_instructions.rb', line 180 def scroll_to(position) @instructions << {scroll_to: position.to_s} self end |
#scroll_x(pixels) ⇒ self
Scroll horizontally
167 168 169 170 |
# File 'lib/zenrows/js_instructions.rb', line 167 def scroll_x(pixels) @instructions << {scroll_x: pixels} self end |
#scroll_y(pixels) ⇒ self
Scroll vertically
158 159 160 161 |
# File 'lib/zenrows/js_instructions.rb', line 158 def scroll_y(pixels) @instructions << {scroll_y: pixels} self end |
#select_option(selector, value) ⇒ self
Select an option from dropdown
145 146 147 148 |
# File 'lib/zenrows/js_instructions.rb', line 145 def select_option(selector, value) @instructions << {select_option: [selector, value]} self end |
#size ⇒ Integer
Number of instructions
263 264 265 |
# File 'lib/zenrows/js_instructions.rb', line 263 def size @instructions.size end |
#to_a ⇒ Array<Hash>
Convert to array
249 250 251 |
# File 'lib/zenrows/js_instructions.rb', line 249 def to_a @instructions.dup end |
#to_json(*_args) ⇒ String
Convert to JSON string for API
242 243 244 |
# File 'lib/zenrows/js_instructions.rb', line 242 def to_json(*_args) @instructions.to_json end |
#uncheck(selector) ⇒ self
Uncheck a checkbox
132 133 134 135 |
# File 'lib/zenrows/js_instructions.rb', line 132 def uncheck(selector) @instructions << {uncheck: selector} self end |
#wait(duration) ⇒ self
Wait for a duration in milliseconds
75 76 77 78 |
# File 'lib/zenrows/js_instructions.rb', line 75 def wait(duration) @instructions << {wait: duration} self end |
#wait_event(event) ⇒ self
Wait for a browser event
100 101 102 103 |
# File 'lib/zenrows/js_instructions.rb', line 100 def wait_event(event) @instructions << {wait_event: event.to_s} self end |
#wait_for(selector) ⇒ self
Wait for an element to appear
88 89 90 91 |
# File 'lib/zenrows/js_instructions.rb', line 88 def wait_for(selector) @instructions << {wait_for: selector} self end |