Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / test / chromedriver / client / webelement.py
blob64d3b31dacbf3f2c6a0f084e7e99c28d8b5e19b5
1 # Copyright 2013 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.
5 from command_executor import Command
8 class WebElement(object):
9 """Represents an HTML element."""
10 def __init__(self, chromedriver, id_):
11 self._chromedriver = chromedriver
12 self._id = id_
14 def _Execute(self, command, params=None):
15 if params is None:
16 params = {}
17 params['id'] = self._id;
18 return self._chromedriver.ExecuteCommand(command, params)
20 def FindElement(self, strategy, target):
21 return self._Execute(
22 Command.FIND_CHILD_ELEMENT, {'using': strategy, 'value': target})
24 def FindElements(self, strategy, target):
25 return self._Execute(
26 Command.FIND_CHILD_ELEMENTS, {'using': strategy, 'value': target})
28 def GetText(self):
29 return self._Execute(Command.GET_ELEMENT_TEXT)
31 def HoverOver(self):
32 self._Execute(Command.HOVER_OVER_ELEMENT)
34 def Click(self):
35 self._Execute(Command.CLICK_ELEMENT)
37 def SingleTap(self):
38 self._Execute(Command.TOUCH_SINGLE_TAP)
40 def DoubleTap(self):
41 self._Execute(Command.TOUCH_DOUBLE_TAP)
43 def LongPress(self):
44 self._Execute(Command.TOUCH_LONG_PRESS)
46 def Clear(self):
47 self._Execute(Command.CLEAR_ELEMENT)
49 def SendKeys(self, *values):
50 typing = []
51 for value in values:
52 if isinstance(value, int):
53 value = str(value)
54 for i in range(len(value)):
55 typing.append(value[i])
56 self._Execute(Command.SEND_KEYS_TO_ELEMENT, {'value': typing})
58 def GetLocation(self):
59 return self._Execute(Command.GET_ELEMENT_LOCATION)
61 def IsDisplayed(self):
62 return self._Execute(Command.IS_ELEMENT_DISPLAYED)