1# Copyright 2014 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5from telemetry.internal.actions import page_action 6 7 8class ClickElementAction(page_action.PageAction): 9 def __init__(self, selector=None, text=None, element_function=None): 10 super(ClickElementAction, self).__init__() 11 self.selector = selector 12 self.text = text 13 self.element_function = element_function 14 15 def RunAction(self, tab): 16 code = ''' 17 function(element, errorMsg) { 18 if (!element) { 19 throw Error('Cannot find element: ' + errorMsg); 20 } 21 element.click(); 22 }''' 23 page_action.EvaluateCallbackWithElement( 24 tab, code, selector=self.selector, text=self.text, 25 element_function=self.element_function) 26