Add tab.elem.find_id

This commit is contained in:
Florian Bruhin 2016-08-18 14:08:34 +02:00
parent afc7faabda
commit 5ac9fe9c32
3 changed files with 17 additions and 0 deletions

View File

@ -433,6 +433,15 @@ class AbstractElements:
"""
raise NotImplementedError
def find_id(self, elem_id, callback):
"""Find the HTML element with the given ID async.
Args:
callback: The callback to be called when the search finished.
elem_id: The ID to search for.
"""
raise NotImplementedError
def find_focused(self, callback):
"""Find the focused element on the page async.

View File

@ -351,6 +351,11 @@ class WebEngineElements(browsertab.AbstractElements):
js_cb = functools.partial(self._js_cb_multiple, callback)
self._tab.run_js_async(js_code, js_cb)
def find_id(self, elem_id, callback):
js_code = javascript.assemble('document', 'getElementById', elem_id)
js_cb = functools.partial(self._js_cb_single, callback)
self._tab.run_js_async(js_code, js_cb)
def find_focused(self, callback):
js_code = javascript.assemble('webelem', 'focus_element')
js_cb = functools.partial(self._js_cb_single, callback)

View File

@ -512,6 +512,9 @@ class WebKitElements(browsertab.AbstractElements):
callback(elems)
def find_id(self, elem_id, callback):
self.find_css('#' + elem_id, callback)
def find_focused(self, callback):
frame = self._widget.page().currentFrame()
if frame is None: