Django client¶
Installation¶
To use the django driver, you need to install
django,
lxml and
cssselect.
You can install all of them in one step by running:
pip install splinter[django]
Usage¶
To use the django driver, all you need to do is pass the string django when you create
the Browser instance:
from splinter import Browser
browser = Browser('django')
Note: if you don’t provide any driver to Browser function, firefox will be used.
API docs¶
-
class
splinter.driver.djangoclient.DjangoClient(user_agent=None, wait_time=2, **kwargs)¶ -
back()¶ The browser will navigate to the previous URL in the history.
If there is no previous URL, this method does nothing.
-
check(name)¶ Check a checkbox by its name.
Parameters: name (str) – name of the element to check. Example
>>> browser.check("agree-with-terms")
If you call
browser.checkn times, the checkbox keeps checked, it never get unchecked.To uncheck a checkbox, take a look in the
uncheckmethod.
-
choose(name, value)¶ Choose a value in a radio buttons group.
Parameters: - name (str) – name of the element to enter text into.
- value (str) – Value to choose.
Example
You have two radio buttons in a page, with the name
genderand values ‘F’ and ‘M’.>>> browser.choose('gender', 'F')
Then the female gender will be chosen.
-
click_link_by_href(href)¶ Click in a link by its
hrefattribute.Parameters: href (str) – href of the element to click.
-
click_link_by_id(id)¶ Clicks in a link by id.
-
click_link_by_partial_href(partial_href)¶ Click in a link by looking for partial content of
hrefattribute.Parameters: partial_href (str) – href of the element to click.
-
click_link_by_partial_text(partial_text)¶ Click in a link by partial content of its text.
Parameters: partial_text (str) – text of the element to click.
-
click_link_by_text(text)¶ Click in a link by its text.
Parameters: text (str) – text of the element to click.
A
CookieManagerinstance.For more details, check the cookies manipulation section.
-
fill(name, value)¶ Fill the field identified by
namewith the content specified byvalue.Parameters: - name (str) – name of the element to enter text into.
- value (str) – Value to enter into the element.
-
fill_form(field_values, form_id=None, name=None, ignore_missing=False)¶ Fill the fields identified by
namewith the content specified byvaluein a dict.Currently, fill_form supports the following fields: text, password, textarea, checkbox, radio and select.
Checkboxes should be specified as a boolean in the dict.
Parameters: - field_values (dict) – Values for all the fields in the form, in the pattern of {field name: field value}
- form_id (str) – Id of the form to fill. Can be used instead of name.
- name (str) – Name of the form to fill.
- ignore_missing (bool) – Ignore missing keys in the dict.
-
find_by_css(selector)¶ Return an instance of
ElementList, using a CSS selector to query the current page content.Parameters: css_selector (str) – CSS Selector to use in the search query.
-
find_by_id(id_value)¶ Find an element on the current page by its id.
Even when only one element is find, this method returns an instance of
ElementListParameters: id (str) – id to use in the search query.
-
find_by_name(name)¶ Find elements on the current page by their name.
Return an instance of
ElementList.Parameters: name (str) – name to use in the search query.
-
find_by_tag(tag)¶ Find all elements of a given tag in current page.
Returns an instance of
ElementListParameters: tag (str) – tag to use in the search query.
-
find_by_text(text)¶ Find elements on the current page by their text.
Returns an instance of
ElementListParameters: text (str) – text to use in the search query.
-
find_by_value(value)¶ Find elements on the current page by their value.
Returns an instance of
ElementListParameters: value (str) – value to use in the search query.
-
find_by_xpath(xpath, original_find=None, original_query=None)¶ Return an instance of
ElementList, using a xpath selector to query the current page content.Parameters: xpath (str) – Xpath to use in the search query.
-
find_link_by_href(href)¶ Find all elements of a given tag in current page.
Returns an instance of
ElementListParameters: href (str) – href to use in the search query.
-
find_link_by_partial_href(partial_href)¶ Find links by looking for a partial
strin their href attribute.Returns an instance of
ElementListParameters: partial_href (str) – partial_href to use in the search query.
-
find_link_by_partial_text(partial_text)¶ Find links by looking for a partial
strin their text.Returns an instance of
ElementListParameters: partial_text (str) – partial_text to use in the search query.
-
find_link_by_text(text)¶ Find links by querying for their text.
Returns an instance of
ElementListParameters: text (str) – text to use in the search query.
-
find_option_by_text(text)¶ Finds
<option>elements by their text.Returns an instance of
ElementListParameters: text (str) – text to use in the search query.
-
find_option_by_value(value)¶ Find
<option>elements by their value.Returns an instance of
ElementListParameters: value (str) – value to use in the search query.
-
forward()¶ The browser will navigate to the next URL in the history.
If there is no URL to forward, this method does nothing.
-
get_alert()¶ Change the context for working with alerts and prompts.
For more details, check the docs about iframes, alerts and prompts
-
get_iframe(name)¶ Change the context for working with iframes.
For more details, check the docs about iframes, alerts and prompts
-
html¶ Source of current page.
-
is_text_present(text, wait_time=None)¶ Check if a piece of text is on the page.
Parameters: - text (str) – text to use in the search query.
- wait_time (int) – Number of seconds to search for the text.
Returns: True if finds a match for the
textand False if not.Return type: bool
-
new_tab(url)¶ The browser will navigate to the given URL in a new tab.
Parameters: url (str) – URL path.
-
quit()¶ Quit the browser, closing its windows (if it has one).
-
reload()¶ Revisits the current URL.
-
screenshot(name=None, suffix=None)¶ Take a screenshot of the current page and save it locally.
Parameters: - name (str) – File name for the screenshot.
- suffix (str) – File extension for the screenshot.
-
select(name, value)¶ Select an
<option>element in an<select>element using thenameof the<select>and thevalueof the<option>.Parameters: - name (str) – name of the option element.
- value (str) – Value to select.
Example
>>> browser.select("state", "NY")
-
title¶ Title of current page.
-
type(name, value, slowly=False)¶ Type a value into an element.
It’s useful to test javascript events like keyPress, keyUp, keyDown, etc.
Parameters: - name (str) – name of the element to enter text into.
- value (str) – Value to enter into the element.
- slowly (bool) – If True, this function returns an iterator which will type one character per iteration.
-
uncheck(name)¶ Uncheck a checkbox by its name.
Parameters: name (str) – name of the element to uncheck. Example
>>> browser.uncheck("send-me-emails")
If you call
brower.uncheckn times, the checkbox keeps unchecked, it never get checked.To check a checkbox, take a look in the
checkmethod.
-
url¶ URL of current page.
-
visit(url)¶ The browser will navigate to the given URL.
Parameters: url (str) – URL path.
-