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

Side by Side Diff: chrome/test/chromedriver/chromedriver.py

Issue 11884058: [chromedriver] Implement commands: findChildElement, findChildElements. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 4
5 import ctypes 5 import ctypes
6 import json 6 import json
7 7
8 class ChromeDriverException(Exception): 8 class ChromeDriverException(Exception):
9 pass 9 pass
10 class NoSuchElement(ChromeDriverException): 10 class NoSuchElement(ChromeDriverException):
11 pass 11 pass
12 class UnknownCommand(ChromeDriverException): 12 class UnknownCommand(ChromeDriverException):
13 pass 13 pass
14 class StaleElementReference(ChromeDriverException):
15 pass
14 class UnknownError(ChromeDriverException): 16 class UnknownError(ChromeDriverException):
15 pass 17 pass
16 class XPathLookupError(ChromeDriverException): 18 class XPathLookupError(ChromeDriverException):
17 pass 19 pass
18 class InvalidSelector(ChromeDriverException): 20 class InvalidSelector(ChromeDriverException):
19 pass 21 pass
20 class SessionNotCreatedException(ChromeDriverException): 22 class SessionNotCreatedException(ChromeDriverException):
21 pass 23 pass
22 class NoSuchSession(ChromeDriverException): 24 class NoSuchSession(ChromeDriverException):
23 pass 25 pass
24 26
25 def _ExceptionForResponse(response): 27 def _ExceptionForResponse(response):
26 exception_class_map = { 28 exception_class_map = {
27 7: NoSuchElement, 29 7: NoSuchElement,
28 9: UnknownCommand, 30 9: UnknownCommand,
31 10: StaleElementReference,
29 13: UnknownError, 32 13: UnknownError,
30 19: XPathLookupError, 33 19: XPathLookupError,
31 32: InvalidSelector, 34 32: InvalidSelector,
32 33: SessionNotCreatedException, 35 33: SessionNotCreatedException,
33 100: NoSuchSession 36 100: NoSuchSession
34 } 37 }
35 status = response['status'] 38 status = response['status']
36 msg = response['value']['message'] 39 msg = response['value']['message']
37 return exception_class_map.get(status, ChromeDriverException)(msg) 40 return exception_class_map.get(status, ChromeDriverException)(msg)
38 41
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 return self._ExecuteSessionCommand('getTitle') 100 return self._ExecuteSessionCommand('getTitle')
98 101
99 def FindElement(self, strategy, target): 102 def FindElement(self, strategy, target):
100 return self._ExecuteSessionCommand( 103 return self._ExecuteSessionCommand(
101 'findElement', {'using': strategy, 'value': target}) 104 'findElement', {'using': strategy, 'value': target})
102 105
103 def FindElements(self, strategy, target): 106 def FindElements(self, strategy, target):
104 return self._ExecuteSessionCommand( 107 return self._ExecuteSessionCommand(
105 'findElements', {'using': strategy, 'value': target}) 108 'findElements', {'using': strategy, 'value': target})
106 109
110 def FindChildElement(self, root_element, strategy, target):
kkania 2013/01/15 22:24:36 we should create a Element class that has these me
chrisgao (Use stgao instead) 2013/01/16 19:06:24 Done.
111 return self._ExecuteSessionCommand(
112 'findChildElement',
113 {'using': strategy, 'value': target, 'id' : root_element})
114
115 def FindChildElements(self, root_element, strategy, target):
116 return self._ExecuteSessionCommand(
117 'findChildElements',
118 {'using': strategy, 'value': target, 'id' : root_element})
119
107 def SetTimeout(self, type, timeout): 120 def SetTimeout(self, type, timeout):
108 return self._ExecuteSessionCommand( 121 return self._ExecuteSessionCommand(
109 'setTimeout', {'type' : type, 'ms': timeout}) 122 'setTimeout', {'type' : type, 'ms': timeout})
110 123
111 def Quit(self): 124 def Quit(self):
112 """Quits the browser and ends the session.""" 125 """Quits the browser and ends the session."""
113 self._ExecuteSessionCommand('quit') 126 self._ExecuteSessionCommand('quit')
OLDNEW
« no previous file with comments | « no previous file | chrome/test/chromedriver/command_executor_impl.cc » ('j') | chrome/test/chromedriver/commands.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698