ported code snippets from WebdriverJS project