有些控件, 通过 driver.element_by_id(id)
能找到, 但是 driver.element_by_id(id).touch('tap')
却不执行点击操作, 没有反应.
通过找到的控件, 获取控件的坐标, 算出控件的中心位置坐标, 然后通过 driver.touch('tap', {'x': x, 'y': y})
点击
def tap_element_center_by_id(value):
element = driver.element_by_id(value)
x, y = tap_element_center(element)
return x, y
def tap_element_center(element):
rect = element.rect
# logging.info('element 坐标: %s' % rect)
x = rect['x'] + rect['width']/2
y = rect['y'] + rect['height']/2
driver.touch('tap', {'x': x, 'y': y})
return x, y