HTMLWrapper and ElementWrapper¶
Warning
All the methods documented here require the target document to include the JS libraries.
-
class
pycommunicate.proxies.dom.html.
HTMLWrapper
¶ This class allows you to get
ElementWrapper
instances, and check for their existance.Every controller and view has one, and these are not created by the user.
-
exists
(selector)¶ Ask the browser whether an element matching the given selector exists. This method will block.
Parameters: selector (str) – The selector to check Returns: Whether or not the target element exists Return type: bool Changed in version 0.0.8: Renamed to exists.
-
element
(selector)¶ First call
exists()
and if it returns True return anElementWrapper
instance tracking the element defined by selector. Otherwise return NoneParameters: selector (str) – The selector for the element Returns: An ElementWrapper
instance tracking the given selector or None if none is found.Return type: pycommunicate.proxies.dom.element.ElementWrapper Changed in version Renamed: to element.
-
-
class
pycommunicate.proxies.dom.element.
ElementWrapper
¶ This class tracks an element by selector, and provides many utility functions and properties for it.
These are created by
HTMLWrapper
and should not be created manually.-
prop
(name, value=None)¶ Wrapper around
get_property()
andset_property()
. This is part of the new chainable API.Calling this without value or with value set to None will result in getting the property and returning its value. Calling this with a value will set the property to value, and return the element. You can chain calls in this way.
Parameters: - name (object) – The name of the property to get/set
- name – The value to set to, if None do a get.
New in version 0.0.8.
-
get_property
(property_name)¶ Get a python representation of JS property named
property_name
. This method will blockParameters: property_name (str) – The name of the JS property to get Returns: The value of the property, coverted to python types where possible
-
set_property
(property_name, value)¶ Set the JS property named
property_name
to a JS representation ofvalue
Warning
The get methods block until the value is received, but the set methods do not block at all. This can cause some odd things, like this:
>>> my_element.set_property('value', 5) >>> my_element.get_property('value') None >>> # ???
There is currently no way to prevent this, but this may change in a future version.
Parameters: - property_name (str) – The name of JS property to set
- value (object) – The value to set it to
Returns: None
-
add_event_listener
(event_name, handler)¶ Add an event handler for the given JS event. The names are in chrome/firefox format, not IE. Some examples of events are
click
,focus
, andblur
.handler()
takes no parameters.Parameters: - event_name (str) – The JS name of the event
- handler (function) – An event handler function
-
add_after
(element_type)¶ Add a new element of type
element_type
after this element, and return it.Parameters: element_type (str) – The type of the element, e.g. p
ordiv
Returns: The new element Return type: pycommunicate.proxies.dom.element.ElementWrapper Changed in version 0.0.8: Renamed to add_after and removed id parameter.
-
add_child
(element_type)¶ Add a new element of type
element_type
as a child of this element, and return it.Parameters: element_type (str) – The type of the element, e.g. p
ordiv
Returns: The new element Return type: pycommunicate.proxies.dom.element.ElementWrapper Changed in version 0.0.8: Renamed to add_child and removed id parameter.
-
add_before
(element_type)¶ Add a new element of type
element_type
before of this element, and return it.Parameters: element_type (str) – The type of the element, e.g. p
ordiv
Returns: The new element Return type: pycommunicate.proxies.dom.element.ElementWrapper New in version 0.0.8.
-
delete
()¶ Delete this element.
Warning
After calling
delete()
, the instance should no longer be used.
The following are wrappers for properties. They are actually descriptors, so you can just use them.
Changed in version 0.0.8: Removed old
get()
andset()
api-
content
¶ Wrapper for
innerText
The following are properties that have more than one value. These use the following syntax (using
style
as an example)>>> my_element.style['marginTop'] '123px' >>> my_element.style['marginTop'] = '456px'
-
style
¶ Wrapper for
style
-