Robot Framework SeleniumLibrary
context.py
Go to the documentation of this file.
1 # Copyright 2008-2011 Nokia Networks
2 # Copyright 2011-2016 Ryan Tomac, Ed Manlove and contributors
3 # Copyright 2016- Robot Framework Foundation
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 from SeleniumLibrary.utils import escape_xpath_value
18 
19 
20 class ContextAware():
21 
22 
27  def __init__(self, ctx):
28  self.ctxctx = ctx
29 
30  @property
31  driver = property
32 
33  def driver(self):
34  return self.ctxctx.driver
35 
36  @property
37  drivers = property
38 
39  def drivers(self):
40  return self.ctxctx._drivers
41 
42  @property
43  element_finder = property
44 
45  def element_finder(self):
46  return self.ctxctx._element_finder
47 
48  @element_finder.setter
49 
50  def element_finder(self, value):
51  self.ctxctx._element_finder = value
52 
53 
72  def find_element(self, locator, tag=None, required=True, parent=None):
73  return self.element_finderelement_finderelement_finderelement_finder.find(locator, tag, True, required, parent)
74 
75 
88  def find_elements(self, locator, tag=None, parent=None):
89  return self.element_finderelement_finderelement_finderelement_finder.find(locator, tag, False, False, parent)
90 
91  def is_text_present(self, text):
92  locator = "xpath://*[contains(., %s)]" % escape_xpath_value(text)
93  return self.find_elementfind_element(locator, required=False) is not None
94 
95  def is_element_enabled(self, locator, tag=None):
96  element = self.find_elementfind_element(locator, tag)
97  return (element.is_enabled() and
98  element.get_attribute('readonly') is None)
99 
100  def is_visible(self, locator):
101  element = self.find_elementfind_element(locator, required=False)
102  return element.is_displayed() if element else None
def __init__(self, ctx)
Base class exposing attributes from the common context.
Definition: context.py:27
def find_element(self, locator, tag=None, required=True, parent=None)
Find element matching locator.
Definition: context.py:72
def find_elements(self, locator, tag=None, parent=None)
Find all elements matching locator.
Definition: context.py:88
def is_element_enabled(self, locator, tag=None)
Definition: context.py:95
def escape_xpath_value(value)
Definition: __init__.py:23