Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1136)

Side by Side Diff: tools/telemetry/telemetry/page/click_element_action.py

Issue 12278015: [Telemetry] Reorganize everything. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Re-add shebangs. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 from telemetry import inspector_runtime 4 from telemetry.core import util
5 from telemetry import page as page_module 5 from telemetry.core import exceptions
6 from telemetry import page_action 6 from telemetry.page import page as page_module
7 from telemetry import util 7 from telemetry.page import page_action
8 8
9 class ClickElementAction(page_action.PageAction): 9 class ClickElementAction(page_action.PageAction):
10 def __init__(self, attributes=None): 10 def __init__(self, attributes=None):
11 super(ClickElementAction, self).__init__(attributes) 11 super(ClickElementAction, self).__init__(attributes)
12 12
13 def RunAction(self, page, tab, previous_action): 13 def RunAction(self, page, tab, previous_action):
14 def DoClick(): 14 def DoClick():
15 assert hasattr(self, 'selector') or hasattr(self, 'text') 15 assert hasattr(self, 'selector') or hasattr(self, 'text')
16 if hasattr(self, 'selector'): 16 if hasattr(self, 'selector'):
17 code = 'document.querySelector(\'' + self.selector + '\').click();' 17 code = 'document.querySelector(\'' + self.selector + '\').click();'
18 try: 18 try:
19 tab.ExecuteJavaScript(code) 19 tab.ExecuteJavaScript(code)
20 except inspector_runtime.EvaluateException: 20 except exceptions.EvaluateException:
21 raise page_action.PageActionFailed( 21 raise page_action.PageActionFailed(
22 'Cannot find element with selector ' + self.selector) 22 'Cannot find element with selector ' + self.selector)
23 else: 23 else:
24 callback_code = 'function(element) { element.click(); }' 24 callback_code = 'function(element) { element.click(); }'
25 try: 25 try:
26 util.FindElementAndPerformAction(tab, self.text, callback_code) 26 util.FindElementAndPerformAction(tab, self.text, callback_code)
27 except inspector_runtime.EvaluateException: 27 except exceptions.EvaluateException:
28 raise page_action.PageActionFailed( 28 raise page_action.PageActionFailed(
29 'Cannot find element with text ' + self.text) 29 'Cannot find element with text ' + self.text)
30 30
31 if hasattr(self, 'wait_for_navigate'): 31 if hasattr(self, 'wait_for_navigate'):
32 tab.PerformActionAndWaitForNavigate(DoClick) 32 tab.PerformActionAndWaitForNavigate(DoClick)
33 elif hasattr(self, 'wait_for_href_change'): 33 elif hasattr(self, 'wait_for_href_change'):
34 old_url = tab.EvaluateJavaScript('document.location.href') 34 old_url = tab.EvaluateJavaScript('document.location.href')
35 DoClick() 35 DoClick()
36 util.WaitFor(lambda: tab.EvaluateJavaScript( 36 util.WaitFor(lambda: tab.EvaluateJavaScript(
37 'document.location.href') != old_url, 60) 37 'document.location.href') != old_url, 60)
38 else: 38 else:
39 DoClick() 39 DoClick()
40 40
41 page_module.Page.WaitForPageToLoad(self, tab, 60) 41 page_module.Page.WaitForPageToLoad(self, tab, 60)
42 tab.WaitForDocumentReadyStateToBeInteractiveOrBetter() 42 tab.WaitForDocumentReadyStateToBeInteractiveOrBetter()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698