Class: Insite::Element
- Inherits:
-
Object
- Object
- Insite::Element
- Extended by:
- Forwardable, ComponentMethods, DOMMethods
- Defined in:
- lib/insite/element/element.rb
Direct Known Subclasses
Anchor, Applet, Area, Audio, BR, Base, Body, Button, Canvas, Cell, CheckBox, Circle, Cursor, DList, Data, DataList, DateField, DateTimeField, Defs, Desc, Details, Directory, Div, ElementCollection, Ellipse, Embed, FieldSet, FileField, Font, ForeignObject, Form, Frame, FrameSet, G, Geometry, Gradient, Graphics, HR, HTMLElement, Hatch, Hatchpath, Head, Heading, Hidden, Html, IFrame, Image, Input, Keygen, LI, Label, Legend, Line, LinearGradient, Map, Marker, Marquee, Media, Menu, MenuItem, Mesh, MeshGradient, Meshpatch, Meshrow, Meta, Metadata, Meter, Mod, OList, Object, OptGroup, Option, Output, Paragraph, Param, Path, Pattern, Picture, Polygon, Polyline, Pre, Progress, Quote, RadialGradient, Radio, Rect, Row, SVG, SVGElement, Script, Select, Solidcolor, Source, Span, Stop, Style, Switch, Symbol, TSpan, Table, TableCaption, TableCell, TableCol, TableDataCell, TableHeaderCell, TableRow, TableSection, Template, TextArea, TextContent, TextField, TextPath, TextPositioning, Time, Title, Track, UList, Unknown, Use, Video, View
Class Attribute Summary collapse
-
.predefined_selector ⇒ Object
readonly
Returns the value of attribute predefined_selector.
Instance Attribute Summary collapse
-
#site ⇒ Object
readonly
Returns the value of attribute site.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
- #classes ⇒ Object
- #collection? ⇒ Boolean
-
#initialize(parent, *args) ⇒ Element
constructor
A new instance of Element.
-
#inspect ⇒ Object
def initialize(site, element) @site = site @browser = @site.browser @target = element.
-
#method_missing(mth, *args, &block) ⇒ Object
For page component code.
- #present? ⇒ Boolean
- #respond_to_missing?(mth, include_priv = false) ⇒ Boolean
Methods included from ElementInstanceMethods
#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, #cell, #cells, #checkbox, #checkboxes, #circle, #circles, #cite, #cites, #code, #codes, #col, #colgroup, #colgroups, #cols, #cursor, #cursors, #data, #datalist, #datalists, #datas, #date_field, #date_fields, #date_time_field, #date_time_fields, #dd, #dds, #defs, #defss, #del, #dels, #desc, #descs, #details, #detailses, #dfn, #dfns, #div, #divs, #dl, #dls, #dt, #dts, #element, #elements, #ellipse, #ellipses, #em, #embed, #embeds, #ems, #field_set, #field_sets, #fieldset, #fieldsets, #figcaption, #figcaptions, #figure, #figures, #file_field, #file_fields, #font, #fonts, #footer, #footers, #foreign_object, #foreign_objects, #form, #forms, #frame, #frames, #frameset, #framesets, #g, #gs, #h1, #h1s, #h2, #h2s, #h3, #h3s, #h4, #h4s, #h5, #h5s, #h6, #h6s, #hatchpath, #hatchpaths, #head, #header, #headers, #heads, #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, #line, #linear_gradient, #linear_gradients, #lines, #link, #links, #lis, #main, #mains, #map, #maps, #mark, #marker, #markers, #marks, #menu, #menuitem, #menuitems, #menus, #mesh, #meshes, #meshgradient, #meshgradients, #meshpatch, #meshpatches, #meshrow, #meshrows, #meta, #metadata, #metadatas, #metas, #meter, #meters, #nav, #navs, #noscript, #noscripts, #object, #objects, #ol, #ols, #optgroup, #optgroups, #option, #options, #output, #outputs, #p, #param, #params, #path, #paths, #pattern, #patterns, #picture, #pictures, #polygon, #polygons, #polyline, #polylines, #pre, #pres, #progress, #progresses, #ps, #q, #qs, #radial_gradient, #radial_gradients, #radio, #radios, #rb, #rbs, #rect, #rects, #row, #rows, #rp, #rps, #rt, #rtc, #rtcs, #rts, #rubies, #ruby, #s, #samp, #samps, #script, #scripts, #section, #sections, #select, #select_list, #select_lists, #selects, #small, #smalls, #solidcolor, #solidcolors, #source, #sources, #span, #spans, #ss, #stop, #stops, #strong, #strongs, #style, #styles, #sub, #subs, #summaries, #summary, #sup, #sups, #svg, #svgs, #switch, #switches, #symbol, #symbols, #table, #tables, #tbody, #tbodys, #td, #tds, #template, #templates, #text_field, #text_fields, #text_path, #text_paths, #textarea, #textareas, #tfoot, #tfoots, #th, #thead, #theads, #ths, #time, #times, #titles, #tr, #track, #tracks, #trs, #tspan, #tspans, #u, #ul, #uls, #us, #use, #uses, #var, #vars, #video, #videos, #view, #views, #wbr, #wbrs
Methods included from CommonMethods
Constructor Details
#initialize(parent, *args) ⇒ Element
Returns a new instance of Element.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/insite/element/element.rb', line 37 def initialize(parent, *args) parent.respond_to?(:target) ? obj = parent : obj = parent.site @parent = obj @site = parent.class.ancestors.include?(Insite) ? parent : parent.site @browser = @site.browser if args[0].is_a?(Insite::Element) || args[0].is_a?(Watir::Element) @target = args[0].target @selector = @target.selector.dup @args = @selector elsif args[0].is_a?(Insite::ElementCollection) || args[0].is_a?(Watir::ElementCollection) @args = nil @selector = @target.instance_variable_get(:@selector).dup @args = @selector else if [Insite::Element, Insite::HTMLElement].include?(self.class) @args = parse_args(args.dup) elsif tag = parse_args(args)[:tag_name] @args = parse_args(args.dup) elsif Insite.class_to_tag(self.class) @args = parse_args(args.dup).merge( tag_name: Insite.class_to_tag(self.class) ) else @args = parse_args(args.dup) end # Figure out the correct query scope. @non_relative = @args.delete(:non_relative) || false if @non_relative @parent = parent.site else parent.respond_to?(:target) ? obj = parent : obj = parent.site @parent = obj end @selector = @args if watir_class = Insite::CLASS_MAP.key(self.class) @target = watir_class.new(@parent.target, @args) else @target = Watir::HTMLElement.new(@parent.target, @args) end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mth, *args, &block) ⇒ Object
For page component code.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/insite/element/element.rb', line 112 def method_missing(mth, *args, &block) if @target.respond_to? mth out = @target.send(mth, *args, &block) elsif @target.class.descendants.any? { |x| x.instance_methods.include? mth } out = @target.to_subtype.send(mth, *args, &block) else super end if out == @target self elsif out.is_a?(Watir::Element) || out.is_a?(Watir::ElementCollection) Insite::CLASS_MAP[out.class].new(@parent, out) else out end end |
Class Attribute Details
.predefined_selector ⇒ Object (readonly)
Returns the value of attribute predefined_selector.
9 10 11 |
# File 'lib/insite/element/element.rb', line 9 def predefined_selector @predefined_selector end |
Instance Attribute Details
#site ⇒ Object (readonly)
Returns the value of attribute site.
6 7 8 |
# File 'lib/insite/element/element.rb', line 6 def site @site end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
6 7 8 |
# File 'lib/insite/element/element.rb', line 6 def target @target end |
Class Method Details
.collection? ⇒ Boolean
19 20 21 |
# File 'lib/insite/element/element.rb', line 19 def self.collection? false end |
Instance Method Details
#attributes ⇒ Object
23 24 25 26 27 |
# File 'lib/insite/element/element.rb', line 23 def attributes nokogiri.xpath("//#{selector[:tag_name]}")[0].attributes.values.map do |x| [x.name, x.value] end.to_h end |
#classes ⇒ Object
29 30 31 |
# File 'lib/insite/element/element.rb', line 29 def classes attribute('class').split end |
#collection? ⇒ Boolean
33 34 35 |
# File 'lib/insite/element/element.rb', line 33 def collection? false end |
#inspect ⇒ Object
def initialize(site, element)
@site = site
@browser = @site.browser
@target = element
# Temporary replacement for custom wait_until.
# TODO: Continue looking at scolling solutions.
if @target.present? && @target.respond_to?(:scroll)
@target.scroll.to
t = ::Time.now + 2
while ::Time.now <= t do
break if @target.present?
sleep 0.1
end
end
@target
end
102 103 104 105 106 107 108 109 |
# File 'lib/insite/element/element.rb', line 102 def inspect if @target.selector.present? s = @selector.to_s else s = '{element: (selenium element)}' end "#<#{self.class}: located: #{!!@target.element}; @selector=#{s}>" end |
#present? ⇒ Boolean
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/insite/element/element.rb', line 130 def present? sleep 0.1 begin if @parent if @parent.respond_to?(:present?) && @parent.present? && @target.present? true else false end else if @target.present? true else false end end rescue => e false end end |
#respond_to_missing?(mth, include_priv = false) ⇒ Boolean
151 152 153 |
# File 'lib/insite/element/element.rb', line 151 def respond_to_missing?(mth, include_priv = false) @target.respond_to?(mth, include_priv) || super end |