OLD | NEW |
| (Empty) |
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 | |
3 # found in the LICENSE file. | |
4 from telemetry import inspector_runtime | |
5 from telemetry import page as page_module | |
6 from telemetry import page_action | |
7 from telemetry import util | |
8 | |
9 class ClickElementAction(page_action.PageAction): | |
10 def __init__(self, attributes=None): | |
11 super(ClickElementAction, self).__init__(attributes) | |
12 | |
13 def RunAction(self, page, tab, previous_action): | |
14 def DoClick(): | |
15 assert hasattr(self, 'selector') or hasattr(self, 'text') | |
16 if hasattr(self, 'selector'): | |
17 code = 'document.querySelector(\'' + self.selector + '\').click();' | |
18 try: | |
19 tab.ExecuteJavaScript(code) | |
20 except inspector_runtime.EvaluateException: | |
21 raise page_action.PageActionFailed( | |
22 'Cannot find element with selector ' + self.selector) | |
23 else: | |
24 callback_code = 'function(element) { element.click(); }' | |
25 try: | |
26 util.FindElementAndPerformAction(tab, self.text, callback_code) | |
27 except inspector_runtime.EvaluateException: | |
28 raise page_action.PageActionFailed( | |
29 'Cannot find element with text ' + self.text) | |
30 | |
31 if hasattr(self, 'wait_for_navigate'): | |
32 tab.PerformActionAndWaitForNavigate(DoClick) | |
33 elif hasattr(self, 'wait_for_href_change'): | |
34 old_url = tab.EvaluateJavaScript('document.location.href') | |
35 DoClick() | |
36 util.WaitFor(lambda: tab.EvaluateJavaScript( | |
37 'document.location.href') != old_url, 60) | |
38 else: | |
39 DoClick() | |
40 | |
41 page_module.Page.WaitForPageToLoad(self, tab, 60) | |
42 tab.WaitForDocumentReadyStateToBeInteractiveOrBetter() | |
OLD | NEW |