HandshakeBrowser¶
-
class
autohandshake.
HandshakeBrowser
(max_wait_time: int = 300, chromedriver_path: str = None, download_dir: str = None)¶ An automated browser for navigating Handshake.
Since a logged-in instance of this class is returned by HandshakeSession’s __enter__ method, it does not usually need to be manually instantiated. Additionally, for most use cases, the user only needs to pass a HandshakeBrowser object to a Page object, then let the Page’s methods do the heavy-lifting.
For example, you almost never need to write:
browser = HandshakeBrowser()
The vast majority of use cases look something like:
with HandshakeSession(school_url, email) as browser: some_page = SomePage(browser) some_page.do_something()
If you need to specify a custom max_wait_time, that can be done through the HandshakeSession object:
# this with HandshakeSession(school_url, email, max_wait_time = 60) as browser: some_page = SomePage(browser) # not this browser = HandshakeBrowser(max_wait_time = 60)
Parameters: - max_wait_time (int) – the maximum time (in seconds) to wait for an element to load before throwing a timeout error
- chromedriver_path (str) – the filepath to chromedriver.exe. If not specified, the package’s own driver will be used
- download_dir (str) – the directory in which to download any files. If not specified, defaults to system’s default download location.
-
click_element_by_xpath
(xpath)¶ Click an element on the page given its xpath
Parameters: xpath (str) – the xpath of the element to click
-
current_url
¶ Get the url of the browser’s current page
-
element_exists_by_xpath
(xpath: str) → bool¶ Determine whether or not an element with the given xpath exists in the page.
Parameters: xpath (str) – the xpath of the element to search for Returns: True if the element exists, false otherwise Return type: bool
-
element_is_selected_by_xpath
(xpath: str) → bool¶ Get whether or not the element specified by the given xpath is selected
Parameters: xpath (str) – the xpath of the elements of interest Returns: True if the element is selected, False otherwise Return type: bool
-
execute_script_on_element_by_xpath
(script: str, xpath: str = None)¶ Execute the given javascript expression. If xpath of element is provided, the element becomes available to use in the script, and can be accessed using arguments[0].
Parameters: - script (str) – the javascript to be executed
- xpath (str) – the xpath of the optional element to be passed to the script
-
get
(url: str)¶ Go to the web page specified by the given Handshake url.
Parameters: url (str) – the url to visit. Must be of the form “https://[…].joinhandshake.com[/…]”
-
get_element_attribute_by_xpath
(xpath: str, attribute: str) → str¶ Get the value of the given attribute from the element with the given xpath
Parameters: - xpath (str) – the xpath of the element of interest
- attribute (str) – the name of the attribute of interest, e.g. ‘value’
Returns: the value of the attribute on the element of interest
Return type: str
-
get_elements_attribute_by_xpath
(xpath: str, attribute: str) → list¶ Get the value of a given attribute for all elements with the given xpath
Parameters: - xpath (str) – the xpath of the elements of interest
- attribute (str) – the name of the attribute of interest, e.g. ‘value’
Returns: a list of values of the given attribute for each matching element
Return type: list
-
maximize_window
()¶ Maximize the browser window.
-
quit
()¶ Close the browser
-
return_to_main_tab
()¶ With a second tab open, close the current tab and return to the main tab.
-
send_text_to_element_by_xpath
(xpath: str, text: str, clear: bool = True)¶ Send a string to an input field identified by the given xpath
Parameters: - text (str) – the text to send
- xpath (str) – the xpath of the input field to which to send the text
- clear (bool) – whether or not to clear the field before sending text. If False, text will be appended to any text already present.
-
switch_to_new_tab
()¶ Wait for the new tab to finish loaded, then switch to it.
-
switch_users
(user_type: autohandshake.src.HandshakeBrowser.UserType)¶ Switch to the system view specified by the given user type.
This method automates the built-in “Switch Users” function in Handshake.
Parameters: user_type (UserType) – the user type to which to switch
-
update_constants
()¶ Update any Handshake environment constants such as School ID or User ID.
This should be done every time the browser switches user types and upon initial login.
-
user_type
¶ Get the user type of the account currently logged into Handshake.
Returns: the browser’s currently-logged-in user type Return type: UserType
-
wait_then_click_element_by_xpath
(xpath)¶ Click an element on the page given its xpath after waiting to make sure it exists
Parameters: xpath (str) – the xpath of the element to click
-
wait_until_element_does_not_exist_by_xpath
(xpath: str)¶ Wait until an element with the given xpath exists on the page.
Parameters: xpath (str) – the xpath of the element to wait for
-
wait_until_element_exists_by_xpath
(xpath: str)¶ Wait until an element with the given xpath exists on the page.
Parameters: xpath (str) – the xpath of the element to wait for
-
wait_until_element_is_clickable_by_xpath
(xpath: str)¶ Wait until an element with the given xpath is clickable.
Parameters: xpath (str) – the xpath of the element to wait for