Elements - skinnyjames/screen-pill GitHub Wiki
Elements
All elements have the following methods
waitUntil(callback(element), {timeout: milliseconds, message: 'custom message'})
waitUntilPresent({timeout: milliseconds, message: 'custom message'})
allElements() // returns promise of selenium elements
element() //returns promise with selenium element
depending on the type of element, there might be extra functionality exposed.
elements are generated by calling them like this
this.h1('accessorName', locator)
where locator is a selenium locator hash
click here for a list of locator properties
Note that locators support an index property, whereas selenium does not.
There is also a generic element method that is called like this
this.element('accessorName', 'elementName', locator)
where element name is a css selector for the element
By making generic elements, one can create accessors for nested elements example:
this.element('importantCell', 'table#important tr:nth-child(3) td', { index: 1 })
now importantCell.element() returns the 2nd cell, of the 3rd row of the table with an id of important
Cool.
Block level and inline
h1, h2, h3, h4, h5, h6, div, span, em, strong, p, ul, ol, li, label, table, tr, td, link
- get() -> returns a promise with the inner text of the element
- click() -> clicks the element
image
- get() -> returns the src attribute of the image
- click() -> clicks the image
Forms
submit, button
- click() -> clicks the element
textField, passwordField, textarea
- get() -> returns a promise with the value of the element
- set(value) -> sets the value of the element
radio
- select(value) -> selects a radio by it's value
- getSelected() -> returns a promise with the selected radio
selectList
- optionElements() -> returns a promise with the webdriver option elements
- options() -> returns a promise with the option texts
- getSelected() -> returns array of promises with selected option texts
- get() -> returns promise with first selected option text
- select(value) -> selects an option by it's visible text
- selectBy(type, token) -> selects an option by it's type ('index' or 'value') and token ( number or string )
- the default behavior is to select an option by it's visible text.
checkbox
- check() -> checks the element
- isChecked() -> returns promise with a boolean telling whether or not the element is checked
file
- get() -> returns promise with the value of the element
- upload(
filename
) -> sets the upload file tofilename