ghostly.ghostly

Lightweight wrapper and helpers around Selenium Webdriver.

class ghostly.ghostly.Ghostly(driver, maximise_window=True)[source]

Bases: object

Lightweight wrapper and helper utilities around Selenium webdriver.

driver = None

:type : webdriver.Chrome

end()[source]
form_fill(xpath, **data)[source]

Fill a simple form with data.

Parameters:
  • xpath – The xpath locator of the form.
  • data – A dict of data on the form to fill. The key of each item should equal the name of an input field.
Returns:

selenium.webdriver.remote.webelement.WebElement

form_submit(xpath, **data)[source]

Submit a form optionally setting (simple) data on the form.

Parameters:
  • xpath – The xpath locator of the form.
  • data – A dict of data to supply to Ghostly.form_fill()
Returns:

selenium.webdriver.remote.webelement.WebElement

get(url)[source]

Load the provided URL in the web driver

wait(seconds)[source]

Wait for a specified number of seconds

xpath(xpath)[source]

Finds an element by xpath.

This simply passes through to WebDriver.find_element_by_xpath.

Parameters:xpath – The xpath locator of the element to find.
Returns:selenium.webdriver.remote.webelement.WebElement
xpath_click(xpath, wait=0.1, move_to=True)[source]

Click an element selected using xpath.

Parameters:
  • xpath – The xpath locator of the element to be clicked or an WebElement
  • wait – Wait after the click - set to None for no wait.
  • move_to – If True (default) then an ActionChains is created and move_to_element called - this approach works well for elements that respond to clicks such as a/span/div tags. If False, click is called on the element - this approach works well for choosing items in a select tag.
xpath_wait(xpath, visible=True, timeout=5, sleep=0.25, click=False, click_move_to=True, click_wait=0.1)[source]

Wait for timeout seconds for xpath to exist and optionally be visible.

Parameters:
  • xpath – The xpath locator of the element to find.
  • visible – If True, also wait for the element to become visible.
  • timeout – Timeout in seconds before GhostlyTimeoutError is raised.
  • sleep – How long to sleep for between each check to see if
  • click – If True, then Ghostly.xpath_click() is called upon completion.
  • click_move_to – Passed onto Ghostly.xpath_click() if click is True.
  • click_wait – Passed onto Ghostly.xpath_click() if click is True.
Returns:

selenium.webdriver.remote.webelement.WebElement