Toturial 10: Selenium bridge

This sections shows several examples how to use Selenium bridge.


Module hydratk.lib.bridge.selen

Constructor requires attribute browser, PhantomJS (headless browser) is chosen by default. Browser libraries including PhantomJS are not bundled with HydraTK and must be installed individually.

Supported browsers:

  • Android
  • BlackBerry
  • Firefox
  • Internet Explorer
  • Opera
  • PhantomJS
  • Safari


  • open: open web page URL

  • close: close browser

  • wait_for_element: wait for element presence

  • get_element: get element using various methods

  • read_element: read element value

  • set_element: set element value

  • exe_script: execute JavaScript code

  • save_screen: save screenshot

  • check_alert: check if alert is present

  • get_current_url: get current url

  • get_title: get page title

  • go_back: emulates browser back button

  • refresh: emulates browser refresh button

  • get_screen: get screenshot content


    API uses HydraTK core functionalities so it must be running.


# import library
from hydratk.lib.bridge.selen import SeleniumBridge

# initialize bridge
bridge = SeleniumBridge('PhantomJS')

# open registration module'')

# wait for element presence

# fill registration form
bridge.set_element('firstName', 'Charlie')
bridge.set_element('lastName', 'Bowman')
bridge.set_element('phoneNumber', '603603603')
bridge.set_element('email', '')
bridge.set_element('marketingAgreement1', False)

# save screenshot

# submit form
bridge.set_element('button', method='tag', attr='text', attr_val='Continue'))

# wait for element presence
bridge.wait_for_element('//input[@class='result']', method='xpath')

# read element text
result = bridge.read_element('//input[@class='result']', method='xpath')
assert (result == 'User registered')

# close browser