WebDriver Plus supports a wide variety of selectors to let you easily locate elements on the page.
To locate elements on the page use the .find() method. Calling .find() will return a set of all the elements that matched the selectors.
import webdriverplus
browser = webdriverplus.WebDriver()
browser.get('http://www.example.com/')
browser.find(id='login-form')
Different types of selector are used depending on the keyword arguments passed to find().
browser.find(id='login-form')
browser.find(tag_name='a')
browser.find(css='#login-form input')
browser.find(link_text='Images')
The default selector for the .find() method is css. If you pass an unnamed argument to .find() it will be treated as a css selector.
browser.find('a') # All 'a' tags
browser.find('a.selected') # All 'a' tags with 'selected' class
browser.find('div#content a') # All 'a' tags within the 'content' div
Multiple selectors can be used in a single expression. The resulting set will be the set of elements that match all the given selectors. TODO
browser.find('input', type='checkbox', checked=True)
Note
When finding elements and traversing the DOM, WebDriver Plus follows the same style as JQuery.
You will always be working with sets of WebElements rather than indivdual elements. Actions on those sets, such as .click(), will applied only to the first element in the set.
The .find() method can be applied either to the browser instance, or to an existing set of elements. When applied to an existing set of elements .find() will return all children of any element in the set that match the given selector.
login = browser.find(id='login-form') # The login form
inputs = login.find('input') # All 'input' tags within the form
Selectors can also be chained in a single expression.
browser.find(id='login-form').find('input')