DriverAPI¶
- class splinter.driver.DriverAPI[source]¶
Basic driver API class.
- back() None[source]¶
The browser will navigate to the previous URL in the history.
If there is no previous URL, this method does nothing.
- check(name: str) None[source]¶
Check a checkbox by its name.
If you call
browser.checkn times, the checkbox keeps checked, it never get unchecked.To uncheck a checkbox, see the
uncheckmethod.Example
>>> browser.check("some-check")
- choose(name: str, value: str) None[source]¶
Choose a value in a radio buttons group.
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.
- property cookies : type[CookieManagerAPI]¶
A
CookieManagerinstance.For more details, check the cookies manipulation section.
- evaluate_script(script: str, *args: str) Any[source]¶
Similar to
execute_scriptmethod.Execute javascript in the browser and return the value of the expression.
Example
>>> assert 4 == browser.evaluate_script('2 + 2')
- execute_script(script: str, *args: str) Any[source]¶
Execute a piece of JavaScript in the browser.
Example
>>> browser.execute_script('document.getElementById("body").innerHTML = "<p>Hello world!</p>"')
- fill(name: str, value: str) None[source]¶
Fill the field identified by
namewith the content specified byvalue.
-
fill_form(field_values, form_id: str | None =
None, name: str | None =None, ignore_missing: bool =False) None[source]¶ 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.
- find(locator)[source]¶
Find an element.
The default strategy used is ‘name’. To change the strategy, see: browser.set_find_strategy()
- find_by_css(css_selector: str) ElementList[source]¶
Return an instance of
ElementList, using a CSS selector to query the current page content.
- find_by_id(id_value: str) ElementList[source]¶
Find an element on the current page by its id.
Even when only one element is find, this method returns an instance of
ElementList
- find_by_name(name: str) ElementList[source]¶
Find elements on the current page by their name.
Return an instance of
ElementList.
- find_by_tag(tag: str) ElementList[source]¶
Find all elements of a given tag in current page.
Returns an instance of
ElementList
- find_by_text(text: str) ElementList[source]¶
Find elements on the current page by their text.
Returns an instance of
ElementList
- find_by_value(value: str) ElementList[source]¶
Find elements on the current page by their value.
Returns an instance of
ElementList
- find_by_xpath(xpath: str) ElementList[source]¶
Return an instance of
ElementList, using a xpath selector to query the current page content.
- find_option_by_text(text: str) ElementList[source]¶
Finds
<option>elements by their text.Returns an instance of
ElementList
- find_option_by_value(value: str) ElementList[source]¶
Find
<option>elements by their value.Returns an instance of
ElementList
- forward() None[source]¶
The browser will navigate to the next URL in the history.
If there is no URL to forward, this method does nothing.
- get_alert() Any[source]¶
Change the context for working with alerts and prompts.
For more details, check the docs about iframes, alerts and prompts
- get_iframe(name: Any) Any[source]¶
Change the context for working with iframes.
For more details, check the docs about iframes, alerts and prompts
- property html : str¶
Source of current page.
-
html_snapshot(name: str =
'', suffix: str ='.html', encoding: str ='utf-8', unique_file: bool =True) str[source]¶ Write the current html to a file.
-
is_element_not_present_by_css(css_selector: str, wait_time: int | None =
None) bool[source]¶ Verify if an element is not present in the current page.
-
is_element_not_present_by_id(id: str, wait_time: int | None =
None) bool[source]¶ Verify if an element is not present in the current page.
-
is_element_not_present_by_name(name: str, wait_time: int | None =
None) bool[source]¶ Verify if an element is not present in the current page.
-
is_element_not_present_by_tag(tag: str, wait_time: int | None =
None) bool[source]¶ Verify if an element is not present in the current page.
-
is_element_not_present_by_text(text: str, wait_time: int | None =
None) bool[source]¶ Verify if an element is not present in the current page.
-
is_element_not_present_by_value(value: str, wait_time: int | None =
None) bool[source]¶ Verify if an element is not present in the current page.
-
is_element_not_present_by_xpath(xpath: str, wait_time: int | None =
None) bool[source]¶ Verify if an element is not present in the current page.
-
is_element_present_by_css(css_selector: str, wait_time: int | None =
None) bool[source]¶ Verify if an element is present in the current page.
-
is_element_present_by_id(id: str, wait_time: int | None =
None) bool[source]¶ Verify if an element is present in the current page.
-
is_element_present_by_name(name: str, wait_time: int | None =
None) bool[source]¶ Verify if an element is present in the current page.
-
is_element_present_by_tag(tag: str, wait_time: int | None =
None) bool[source]¶ Verify if an element is present in the current page.
-
is_element_present_by_text(text: str, wait_time: int | None =
None) bool[source]¶ Verify if an element is present in the current page.
-
is_element_present_by_value(value: str, wait_time: int | None =
None) bool[source]¶ Verify if an element is present in the current page.
-
is_element_present_by_xpath(xpath: str, wait_time: int | None =
None) bool[source]¶ Verify if an element is present in the current page.
-
is_text_present(text: str, wait_time: int | None =
None) bool[source]¶ Check if a piece of text is on the page.
-
screenshot(name: str | None =
None, suffix: str | None =None, full: bool =False, unique_file: bool =True) str[source]¶ 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.
- full : bool¶
If the screenshot should be full screen or not.
- unique_file : bool¶
If true, the filename will include a path to the system temp directory and extra characters at the end to ensure the file is unique.
- Returns:¶
Full file name of the created screenshot.
- Return type:¶
str
- select(name: str, value: str) None[source]¶
Select an
<option>element in an<select>element using thenameof the<select>and thevalueof the<option>.Example
>>> browser.select("pets", "cat")
- property title : str¶
Title of current page.
-
type(name: str, value: str, slowly: bool =
False) str[source]¶ Type a value into an element.
It’s useful to test javascript events like keyPress, keyUp, keyDown, etc.
- uncheck(name: str) None[source]¶
Uncheck a checkbox by its name.
Example
>>> browser.uncheck("some-check")If you call
brower.uncheckn times, the checkbox keeps unchecked, it never get checked.To check a checkbox, take a look in the
checkmethod.
- property url : str¶
URL of current page.
ElementAPI¶
- class splinter.driver.ElementAPI[source]¶
Basic element API class.
Any element in the page can be represented as an instance of
ElementAPI.Once you have an instance, you can easily access attributes like a
dict:>>> element = browser.find_by_id("foo").first >>> assert element['href'] == 'http://localhost:5000/foo'You can also interact with the instance using the methods and properties listed below.
- check() None[source]¶
Check the element, if it’s “checkable” (e.g.: a checkbox).
If the element is already checked, this method does nothing. For unchecking elements, take a loot in the
uncheckmethod.Example
>>> browser.find_by_css("[name='some-check']").uncheck()
- property checked : bool¶
Get the checked status of the element.
Example
>>> elem = browser.find_by_css("[name='some-check']") >>> elem.check() >>> assert elem.checked >>> elem.uncheck() >>> assert not elem.checked
- has_class(class_name: str) bool[source]¶
Indicates whether the element has the given class.
-
is_not_visible(wait_time: int | None =
None) bool[source]¶ Check if an element is not visible within the given wait time.
-
is_visible(wait_time: int | None =
None) bool[source]¶ Check if an element is visible within the given wait time.
-
screenshot(name: str | None =
None, suffix: str | None =None, full: bool =False, unique_file: bool =True) str[source]¶ Take a screenshot of the element.
-
select(value: str, slowly: bool =
False) None[source]¶ Select an
<option>element in the element using thevalueof the<option>.Example
>>> browser.find_by_css("[name='pets']").select("cat")
- property shadow_root¶
Get the shadow root of an element’s shadow DOM.
- property text : str¶
All of the text within the element. HTML tags are stripped.
-
type(value: str, slowly: bool =
False) str[source]¶ Type the
valuein the element.If
slowlyis True, this function returns an iterator which will type one character per iteration.It’s useful to test javascript events like keyPress, keyUp, keyDown, etc.
Example
>>> from selenium.webdriver.common.keys import Keys >>> browser.find_by_css("[name='q']").type(Keys.RETURN)
- uncheck() None[source]¶
Uncheck the element, if it’s “checkable” (e.g.: a checkbox).
If the element is already unchecked, this method does nothing. For checking elements, take a loot in the
checkmethod.Example
>>> browser.find_by_css("[name='some-check']").uncheck()
- property value : str¶
Value of the element, usually a form element