Class: Async::WebDriver::Element::Attributes

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/async/webdriver/element.rb

Overview

Attributes associated with an element.

Instance Method Summary collapse

Constructor Details

#initialize(element) ⇒ Attributes

Returns a new instance of Attributes.



23
24
25
26
# File 'lib/async/webdriver/element.rb', line 23

def initialize(element)
	@element = element
	@keys = nil
end

Instance Method Details

#[](name) ⇒ Object

Get the value of an attribute.



31
32
33
# File 'lib/async/webdriver/element.rb', line 31

def [](name)
	@element.attribute(name)
end

#[]=(name, value) ⇒ Object

Set the value of an attribute.



38
39
40
# File 'lib/async/webdriver/element.rb', line 38

def []=(name, value)
	@element.set_attribute(name, value)
end

#each(&block) ⇒ Object

Iterate over all attributes.



58
59
60
61
62
63
64
# File 'lib/async/webdriver/element.rb', line 58

def each(&block)
	return to_enum unless block_given?
	
	keys.each do |key|
		yield key, self[key]
	end
end

#key?(name) ⇒ Boolean

Check if an attribute exists.

Returns:

  • (Boolean)


50
51
52
# File 'lib/async/webdriver/element.rb', line 50

def key?(name)
	@element.execute("return this.hasAttribute(...arguments)", name)
end

#keysObject

Get the names of all attributes.



43
44
45
# File 'lib/async/webdriver/element.rb', line 43

def keys
	@element.execute("return this.getAttributeNames()")
end