selenious package

Submodules

selenious.decorators module

selenious.decorators.find_element(func)[source]
selenious.decorators.find_elements(func)[source]

selenious.helpers module

selenious.helpers.validate_time_settings(implicitly_wait, timeout, poll_frequency)[source]

Verifies that implicitly_wait isn’t larger than timeout or poll_frequency.

selenious.recover module

class selenious.recover.RecoverData(webdriver, func_id, function, args, kwargs, element=None, elements=None, exception=None, attempts=1, elapsed=0)[source]

Bases: object

class selenious.recover.RecoverFuncId[source]

Bases: enum.Enum

An enumeration.

ELEMENT_CLICK = 5
ELEMENT_FIND_ELEMENT = 3
ELEMENT_FIND_ELEMENTS = 4
FIND_ELEMENT = 1
FIND_ELEMENTS = 2

selenious.webdriver module

selenious.webdriver_mixin module

class selenious.webdriver_mixin.WebDriverMixin(*args, **kwargs)[source]

Bases: object

Enhances the selenium.webdriver.remote.webdriver.WebDriver with several enhanced capabilities.

debounce

The wait time for a select to have not changed.

find_element(by='id', value=None, timeout=None, poll_frequency=None, recover=None)[source]

Finds an element by selenium.webdriver.common.by and value. :Args:

  • by - One of By.ID (default), By.XPATH, By.LINK_TEXT, By.PARTIAL_LINK_TEXT,
    By.NAME, By.TAG_NAME, By.CLASS_NAME, By.CSS_SELECTOR
  • value - The value to search for.
  • timeout - The timeout to wait for element. Default is WebDriverMixin.timeout (0.0)
  • poll_frequency - How often to poll Selenious for the element if there is a timeout. Default is WebDriverMixin.poll_frequency (0.5)
  • recover - A function called after each poll (but not the last) Default is WebDriverMixin.recover (None)
Returns:
  • SeleniousWebElement - the element if it was found
Raises:
  • NoSuchElementException - if the element wasn’t found
Usage:
::

element = driver.find_element(By.ID, ‘foo’)

find_element_by_class_name(class_name, **kwargs)[source]

Calls find_element(By.CLASS_NAME, class_name, **kwargs)

find_element_by_css_selector(css_selector, **kwargs)[source]

Calls find_element(By.CSS_SELECTOR, css_selector, **kwargs)

find_element_by_id(id_, **kwargs)[source]

Calls find_element(By.ID, value=id_, **kwargs)

Calls find_element(By.LINK_TEXT, link_text, **kwargs)

find_element_by_name(name, **kwargs)[source]

Calls find_element(By.NAME, name, **kwargs)

calls find_element(By.PARTIAL_LINK_TEXT, partial_link_text, **kwargs)

find_element_by_tag_name(tag_name, **kwargs)[source]

Calls find_element(By.TAG_NAME, tag_name, **kwargs)

find_element_by_xpath(xpath, **kwargs)[source]

Calls find_element(By.XPATH, xpath, **kwargs)

find_elements(by='id', value=None, timeout=None, poll_frequency=None, recover=None, min=None, debounce=None)[source]

Finds multiple elements by selenium.webdriver.common.by and value. :Args:

  • by - One of By.ID (default), By.XPATH, By.LINK_TEXT, By.PARTIAL_LINK_TEXT, By.NAME, By.TAG_NAME, By.CLASS_NAME, By.CSS_SELECTOR
  • value - The value to search for.
  • timeout - The timeout to wait for min elements. Default is WebDriverMixin.timeout (0)
  • poll_frequency - How often to poll Selenious for the element if there is a timeout. Default is WebDriverMixin.poll_frequency (0.5)
  • recover - A function called after each poll (but not the last) Default is WebDriverMixin.recover (None) :Returns:
  • list of SeleniousWebElement - the element if it was found. An empty list if not
  • min - The minimum number of elements to wait for. Default is 0.
  • debounce - A time to wait for the number of elements to not change. Default is WebDriverMixin.debounce (0.0)
Usage:
::

elements = driver.find_elements(By.ID, ‘foo’)

find_elements_by_class_name(class_name, **kwargs)[source]

calls find_elements(By.CLASS_NAME, class_name, **kwargs)

find_elements_by_css_selector(css_selector, **kwargs)[source]

calls find_elements(By.CSS_SELECTOR, css_selector, **kwargs)

find_elements_by_id(id_, **kwargs)[source]

calls find_elements(By.ID, id_, **kwargs)

Calls find_elements(By.LINK_TEXT, link_text, **kwargs)

find_elements_by_name(name, **kwargs)[source]

calls find_elements(By.NAME, name, **kwargs)

calls find_elements(By.PARTIAL_LINK_TEXT, partial_link_text, **kwargs)

find_elements_by_tag_name(tag_name, **kwargs)[source]

calls find_elements(By.TAG_NAME, tag_name, **kwargs)

find_elements_by_xpath(xpath, **kwargs)[source]

calls find_elements(By.XPATH, xpath, **kwargs)

implicitly_wait(time_to_wait)[source]
Sets a sticky timeout to implicitly wait for an element to be found,
or a command to complete. This method only needs to be called one time per session. To set the timeout for calls to execute_async_script, see set_script_timeout.

Warning: The selenious package will fail if implicitly_wait is larger than timeout or poll_frequency. It is better to not set this and instead use the timeout property.

Args:
  • time_to_wait: Amount of time to wait (in seconds)
Usage:

driver.implicitly_wait(30)

poll_frequency

The frequency polling will happen for the timeout.

This is similar to the WebDriverWait polling frequency. See set_timeout() for differences.

recover

The recover function.

The recover function is run when a select fails or some actions like click fail. The intent is to try to fix expected, but not typical web activities like an advertising popup covering the page being manipulated.

The recovery function is guaranteed to be run at least once if there is an issue, but may be run multiple times at the poll_frequency if there is a timeout.

Args:
  • recover - The recover function to be run. Parameters are: - webdriver - This webdriver (self) - function - The function calling the recover function. - kwargs - The kwargs sent to the function - elapsed - The time elapsed since the first attempt. - attempts - The number of attempts
timeout

The default selenious timout.

The selenium webdriver has an implicitly_wait() command that once set cannot be overwritten. There is also a WebDriverWait() facility to allow requests with a wait. This command moves an equivalent to that capability directly into the select commands. You can specify a global wait timeout with timeout property or pass a timeout parameter directly to the select command.

selenious.webelement module

class selenious.webelement.SeleniousWebElementMixin[source]

Bases: object

click(recover=None)[source]

[summary]

Parameters:recover (function) – A function to be called once if the click fails. Defaults to self.recover (None).

The recover selenious enhancement works similar to the find_element[s]() recover function except that it is only called once if it exists.

debounce

The wait time for a select to have not changed.

find_element(by='id', value=None, timeout=None, poll_frequency=None, recover=None)[source]

Finds an element by selenium.webdriver.common.by and value. :Args: - by - One of By.ID (default), By.XPATH, By.LINK_TEXT, By.PARTIAL_LINK_TEXT,

By.NAME, By.TAG_NAME, By.CLASS_NAME, By.CSS_SELECTOR
  • value - The value to search for.
  • timeout - The timeout to wait for element.

Default is WebDriverMixin.timeout (0.0) - poll_frequency - How often to poll Selenious for the element if there is a timeout. Default is WebDriverMixin.poll_frequency (0.5) - recover - A function called after each poll (but not the last) Default is WebDriverMixin.recover (None) :Returns: - SeleniousWebElement - the element if it was found :Raises: - NoSuchElementException - if the element wasn’t found :Usage:

::
element = driver.find_element(By.ID, ‘foo’)
find_element_by_class_name(class_name, **kwargs)[source]

Calls find_element(By.CLASS_NAME, class_name, **kwargs)

find_element_by_css_selector(css_selector, **kwargs)[source]

Calls find_element(By.CSS_SELECTOR, css_selector, **kwargs)

find_element_by_id(id_, **kwargs)[source]

Calls find_element(By.ID, value=id_, **kwargs)

Calls find_element(By.LINK_TEXT, link_text, **kwargs)

find_element_by_name(name, **kwargs)[source]

Calls find_element(By.NAME, name, **kwargs)

calls find_element(By.PARTIAL_LINK_TEXT, partial_link_text, **kwargs)

find_element_by_tag_name(tag_name, **kwargs)[source]

Calls find_element(By.TAG_NAME, tag_name, **kwargs)

find_element_by_xpath(xpath, **kwargs)[source]

Calls find_element(By.XPATH, xpath, **kwargs)

find_elements(by='id', value=None, timeout=None, poll_frequency=None, recover=None, min=None, debounce=None)[source]

Finds multiple elements by selenium.webdriver.common.by and value. :Args: - by - One of By.ID (default), By.XPATH, By.LINK_TEXT, By.PARTIAL_LINK_TEXT, By.NAME, By.TAG_NAME, By.CLASS_NAME, By.CSS_SELECTOR - value - The value to search for. - timeout - The timeout to wait for min elements. Default is WebDriverMixin.timeout (0) - poll_frequency - How often to poll Selenious for the element if there is a timeout. Default is WebDriverMixin.poll_frequency (0.5) - recover - A function called after each poll (but not the last) Default is WebDriverMixin.recover (None) :Returns: - list of SeleniousWebElement - the element if it was found. An empty list if not - min - The minimum number of elements to wait for. Default is 0. - debounce - A time to wait for the number of elements to not change. Default is WebDriverMixin.debounce (0.0) :Usage:

::
elements = driver.find_elements(By.ID, ‘foo’)
find_elements_by_class_name(class_name, **kwargs)[source]

calls find_elements(By.CLASS_NAME, class_name, **kwargs)

find_elements_by_css_selector(css_selector, **kwargs)[source]

calls find_elements(By.CSS_SELECTOR, css_selector, **kwargs)

find_elements_by_id(id_, **kwargs)[source]

calls find_elements(By.ID, id_, **kwargs)

Calls find_elements(By.LINK_TEXT, link_text, **kwargs)

find_elements_by_name(name, **kwargs)[source]

calls find_elements(By.NAME, name, **kwargs)

calls find_elements(By.PARTIAL_LINK_TEXT, partial_link_text, **kwargs)

find_elements_by_tag_name(tag_name, **kwargs)[source]

calls find_elements(By.TAG_NAME, tag_name, **kwargs)

find_elements_by_xpath(xpath, **kwargs)[source]

calls find_elements(By.XPATH, xpath, **kwargs)

poll_frequency

The frequency polling will happen for the timeout.

This is similar to the WebDriverWait polling frequency. See set_timeout() for differences.

recover

The recover function.

The recover function is run when a select fails or some actions like click fail. The intent is to try to fix expected, but not typical web activities like an advertising popup covering the page being manipulated.

The recovery function is guaranteed to be run at least once if there is an issue, but may be run multiple times at the poll_frequency if there is a timeout.

Args:
  • recover - The recover function to be run. Parameters are:
  • webdriver - This webdriver (self.parent)
  • function - The function calling the recover function.
  • kwargs - The kwargs sent to the function
  • elapsed - The time elapsed since the first attempt.
  • attempts - The number of attempts
timeout

The default selenious timout.

The selenium webdriver has an implicitly_wait() command that once set cannot be overwritten. There is also a WebDriverWait() facility to allow requests with a wait. This command moves an equivalent to that capability directly into the select commands. You can specify a global wait timeout with timeout property or pass a timeout parameter directly to the select command.

selenious.webelement.SeleniousWrapWebElement(instance)[source]

Module contents

class selenious.WebDriverMixin(*args, **kwargs)[source]

Bases: object

Enhances the selenium.webdriver.remote.webdriver.WebDriver with several enhanced capabilities.

debounce

The wait time for a select to have not changed.

find_element(by='id', value=None, timeout=None, poll_frequency=None, recover=None)[source]

Finds an element by selenium.webdriver.common.by and value. :Args:

  • by - One of By.ID (default), By.XPATH, By.LINK_TEXT, By.PARTIAL_LINK_TEXT,
    By.NAME, By.TAG_NAME, By.CLASS_NAME, By.CSS_SELECTOR
  • value - The value to search for.
  • timeout - The timeout to wait for element. Default is WebDriverMixin.timeout (0.0)
  • poll_frequency - How often to poll Selenious for the element if there is a timeout. Default is WebDriverMixin.poll_frequency (0.5)
  • recover - A function called after each poll (but not the last) Default is WebDriverMixin.recover (None)
Returns:
  • SeleniousWebElement - the element if it was found
Raises:
  • NoSuchElementException - if the element wasn’t found
Usage:
::

element = driver.find_element(By.ID, ‘foo’)

find_element_by_class_name(class_name, **kwargs)[source]

Calls find_element(By.CLASS_NAME, class_name, **kwargs)

find_element_by_css_selector(css_selector, **kwargs)[source]

Calls find_element(By.CSS_SELECTOR, css_selector, **kwargs)

find_element_by_id(id_, **kwargs)[source]

Calls find_element(By.ID, value=id_, **kwargs)

Calls find_element(By.LINK_TEXT, link_text, **kwargs)

find_element_by_name(name, **kwargs)[source]

Calls find_element(By.NAME, name, **kwargs)

calls find_element(By.PARTIAL_LINK_TEXT, partial_link_text, **kwargs)

find_element_by_tag_name(tag_name, **kwargs)[source]

Calls find_element(By.TAG_NAME, tag_name, **kwargs)

find_element_by_xpath(xpath, **kwargs)[source]

Calls find_element(By.XPATH, xpath, **kwargs)

find_elements(by='id', value=None, timeout=None, poll_frequency=None, recover=None, min=None, debounce=None)[source]

Finds multiple elements by selenium.webdriver.common.by and value. :Args:

  • by - One of By.ID (default), By.XPATH, By.LINK_TEXT, By.PARTIAL_LINK_TEXT, By.NAME, By.TAG_NAME, By.CLASS_NAME, By.CSS_SELECTOR
  • value - The value to search for.
  • timeout - The timeout to wait for min elements. Default is WebDriverMixin.timeout (0)
  • poll_frequency - How often to poll Selenious for the element if there is a timeout. Default is WebDriverMixin.poll_frequency (0.5)
  • recover - A function called after each poll (but not the last) Default is WebDriverMixin.recover (None) :Returns:
  • list of SeleniousWebElement - the element if it was found. An empty list if not
  • min - The minimum number of elements to wait for. Default is 0.
  • debounce - A time to wait for the number of elements to not change. Default is WebDriverMixin.debounce (0.0)
Usage:
::

elements = driver.find_elements(By.ID, ‘foo’)

find_elements_by_class_name(class_name, **kwargs)[source]

calls find_elements(By.CLASS_NAME, class_name, **kwargs)

find_elements_by_css_selector(css_selector, **kwargs)[source]

calls find_elements(By.CSS_SELECTOR, css_selector, **kwargs)

find_elements_by_id(id_, **kwargs)[source]

calls find_elements(By.ID, id_, **kwargs)

Calls find_elements(By.LINK_TEXT, link_text, **kwargs)

find_elements_by_name(name, **kwargs)[source]

calls find_elements(By.NAME, name, **kwargs)

calls find_elements(By.PARTIAL_LINK_TEXT, partial_link_text, **kwargs)

find_elements_by_tag_name(tag_name, **kwargs)[source]

calls find_elements(By.TAG_NAME, tag_name, **kwargs)

find_elements_by_xpath(xpath, **kwargs)[source]

calls find_elements(By.XPATH, xpath, **kwargs)

implicitly_wait(time_to_wait)[source]
Sets a sticky timeout to implicitly wait for an element to be found,
or a command to complete. This method only needs to be called one time per session. To set the timeout for calls to execute_async_script, see set_script_timeout.

Warning: The selenious package will fail if implicitly_wait is larger than timeout or poll_frequency. It is better to not set this and instead use the timeout property.

Args:
  • time_to_wait: Amount of time to wait (in seconds)
Usage:

driver.implicitly_wait(30)

poll_frequency

The frequency polling will happen for the timeout.

This is similar to the WebDriverWait polling frequency. See set_timeout() for differences.

recover

The recover function.

The recover function is run when a select fails or some actions like click fail. The intent is to try to fix expected, but not typical web activities like an advertising popup covering the page being manipulated.

The recovery function is guaranteed to be run at least once if there is an issue, but may be run multiple times at the poll_frequency if there is a timeout.

Args:
  • recover - The recover function to be run. Parameters are: - webdriver - This webdriver (self) - function - The function calling the recover function. - kwargs - The kwargs sent to the function - elapsed - The time elapsed since the first attempt. - attempts - The number of attempts
timeout

The default selenious timout.

The selenium webdriver has an implicitly_wait() command that once set cannot be overwritten. There is also a WebDriverWait() facility to allow requests with a wait. This command moves an equivalent to that capability directly into the select commands. You can specify a global wait timeout with timeout property or pass a timeout parameter directly to the select command.