Robot Framework SeleniumLibrary
element.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 from collections import namedtuple
17 
18 from robot.utils import plural_or_not
19 from selenium.webdriver.common.action_chains import ActionChains
20 from selenium.webdriver.common.keys import Keys
21 
22 
23 from SeleniumLibrary.base import LibraryComponent, keyword
24 from SeleniumLibrary.utils import (is_falsy, is_noney, is_truthy,
25  plural_or_not as s)
26 from SeleniumLibrary.errors import ElementNotFound
27 
28 
30 
31  @keyword(name='Get WebElement')
32 
37  def get_webelement(self, locator):
38  return self.find_elementfind_element(locator)
39 
40  @keyword(name='Get WebElements')
41 
50  def get_webelements(self, locator):
51  return self.find_elementsfind_elements(locator)
52 
53  @keyword
54 
70  def element_should_contain(self, locator, expected, message=None, ignore_case=False):
71  actual = actual_before = self.find_elementfind_element(locator).text
72  expected_before = expected
73  if is_truthy(ignore_case):
74  actual = actual.lower()
75  expected = expected.lower()
76  if expected not in actual:
77  if is_noney(message):
78  message = "Element '%s' should have contained text '%s' but "\
79  "its text was '%s'." % (locator, expected_before, actual_before)
80  raise AssertionError(message)
81  self.infoinfo("Element '%s' contains text '%s'." % (locator, expected_before))
82 
83  @keyword
84 
97  def element_should_not_contain(self, locator, expected, message=None, ignore_case=False):
98  actual = self.find_elementfind_element(locator).text
99  expected_before = expected
100  if is_truthy(ignore_case):
101  actual = actual.lower()
102  expected = expected.lower()
103  if expected in actual:
104  if is_noney(message):
105  message = "Element '%s' should not contain text '%s' but " \
106  "it did." % (locator, expected_before)
107  raise AssertionError(message)
108  self.infoinfo("Element '%s' does not contain text '%s'."
109  % (locator, expected_before))
110 
111  @keyword
112 
120  def page_should_contain(self, text, loglevel='TRACE'):
121  if not self._page_contains_page_contains(text):
122  self.ctxctx.log_source(loglevel)
123  raise AssertionError("Page should have contained text '%s' "
124  "but did not." % text)
125  self.infoinfo("Current page contains text '%s'." % text)
126 
127  @keyword
128 
152  def page_should_contain_element(self, locator, message=None,
153  loglevel='TRACE', limit=None):
154  if is_noney(limit):
155  return self.assert_page_containsassert_page_contains(locator, message=message,
156  loglevel=loglevel)
157  limit = int(limit)
158  count = len(self.find_elementsfind_elements(locator))
159  if count == limit:
160  self.infoinfo('Current page contains {} element(s).'.format(count))
161  else:
162  if is_noney(message):
163  message = ('Page should have contained "{}" element(s), '
164  'but it did contain "{}" element(s).'
165  .format(limit, count))
166  self.ctxctx.log_source(loglevel)
167  raise AssertionError(message)
168 
169  @keyword
170 
171  def locator_should_match_x_times(self, locator, x, message=None, loglevel='TRACE'):
172  count = len(self.find_elementsfind_elements(locator))
173  x = int(x)
174  if count != x:
175  if is_falsy(message):
176  message = ("Locator '%s' should have matched %s time%s but "
177  "matched %s time%s."
178  % (locator, x, s(x), count, s(count)))
179  self.ctxctx.log_source(loglevel)
180  raise AssertionError(message)
181  self.infoinfo("Current page contains %s elements matching '%s'."
182  % (count, locator))
183 
184  @keyword
185 
190  def page_should_not_contain(self, text, loglevel='TRACE'):
191  if self._page_contains_page_contains(text):
192  self.ctxctx.log_source(loglevel)
193  raise AssertionError("Page should not have contained text '%s'."
194  % text)
195  self.infoinfo("Current page does not contain text '%s'." % text)
196 
197  @keyword
198 
206  def page_should_not_contain_element(self, locator, message=None, loglevel='TRACE'):
207  self.assert_page_not_containsassert_page_not_contains(locator, message=message,
208  loglevel=loglevel)
209 
210  @keyword
211 
224  def assign_id_to_element(self, locator, id):
225  self.infoinfo("Assigning temporary id '%s' to element '%s'." % (id, locator))
226  element = self.find_elementfind_element(locator)
227  self.driverdriverdriver.execute_script("arguments[0].id = '%s';" % id, element)
228 
229  @keyword
230 
238  def element_should_be_disabled(self, locator):
239  if self.is_element_enabledis_element_enabled(locator):
240  raise AssertionError("Element '%s' is enabled." % locator)
241 
242  @keyword
243 
251  def element_should_be_enabled(self, locator):
252  if not self.is_element_enabledis_element_enabled(locator):
253  raise AssertionError("Element '%s' is disabled." % locator)
254 
255  @keyword
256 
263  def element_should_be_focused(self, locator):
264  element = self.find_elementfind_element(locator)
265  focused = self.driverdriverdriver.switch_to.active_element
266  # Selenium 3.6.0 with Firefox return dict wich contains the selenium WebElement
267  if isinstance(focused, dict):
268  focused = focused['value']
269  if element != focused:
270  raise AssertionError("Element '%s' does not have focus." % locator)
271 
272  @keyword
273 
286  def element_should_be_visible(self, locator, message=None):
287  if not self.find_elementfind_element(locator).is_displayed():
288  if is_noney(message):
289  message = ("The element '%s' should be visible, but it "
290  "is not." % locator)
291  raise AssertionError(message)
292  self.infoinfo("Element '%s' is displayed." % locator)
293 
294  @keyword
295 
300  def element_should_not_be_visible(self, locator, message=None):
301  element = self.find_elementfind_element(locator, required=False)
302  if element is None:
303  self.infoinfo("Element '%s' did not exist." % locator)
304  elif not element.is_displayed():
305  self.infoinfo("Element '%s' exists but is not displayed." % locator)
306  else:
307  if is_noney(message):
308  message = ("The element '%s' should not be visible, "
309  "but it is." % locator)
310  raise AssertionError(message)
311 
312  @keyword
313 
328  def element_text_should_be(self, locator, expected, message=None, ignore_case=False):
329  self.infoinfo("Verifying element '%s' contains exact text '%s'."
330  % (locator, expected))
331  text = before_text = self.find_elementfind_element(locator).text
332  if is_truthy(ignore_case):
333  text = text.lower()
334  expected = expected.lower()
335  if text != expected:
336  if is_noney(message):
337  message = ("The text of element '%s' should have been '%s' "
338  "but it was '%s'."
339  % (locator, expected, before_text))
340  raise AssertionError(message)
341 
342  @keyword
343 
356  def element_text_should_not_be(self, locator, not_expected, message=None, ignore_case=False):
357  self.infoinfo("Verifying element '%s' does not contains exact text '%s'."
358  % (locator, not_expected))
359  text = self.find_elementfind_element(locator).text
360  before_not_expected = not_expected
361  if is_truthy(ignore_case):
362  text = text.lower()
363  not_expected = not_expected.lower()
364  if text == not_expected:
365  if is_noney(message):
366  message = ("The text of element '%s' was not supposed to be '%s'."
367  % (locator, before_not_expected))
368  raise AssertionError(message)
369 
370  @keyword
371 
383  def get_element_attribute(self, locator, attribute):
384  return self.find_elementfind_element(locator).get_attribute(attribute)
385 
386  @keyword
387 
397  def element_attribute_value_should_be(self, locator, attribute, expected, message=None):
398  current_expected = self.find_elementfind_element(locator).get_attribute(attribute)
399  if current_expected != expected:
400  if is_noney(message):
401  message = ("Element '%s' attribute should have value '%s' but "
402  "its value was '%s'." % (locator, expected, current_expected))
403  raise AssertionError(message)
404  self.infoinfo("Element '%s' attribute '%s' contains value '%s'." % (locator, attribute, expected))
405 
406  @keyword
407 
417  def get_horizontal_position(self, locator):
418  return self.find_elementfind_element(locator).location['x']
419 
420  @keyword
421 
431  def get_element_size(self, locator):
432  element = self.find_elementfind_element(locator)
433  return element.size['width'], element.size['height']
434 
435  @keyword
436 
446  def cover_element(self, locator):
447  elements = self.find_elementsfind_elements(locator)
448  if not elements:
449  raise ElementNotFound("No element with locator '%s' found."
450  % locator)
451  for element in elements:
452  script = """
453 old_element = arguments[0];
454 let newDiv = document.createElement('div');
455 newDiv.setAttribute("name", "covered");
456 newDiv.style.backgroundColor = 'blue';
457 newDiv.style.zIndex = '999';
458 newDiv.style.top = old_element.offsetTop + 'px';
459 newDiv.style.left = old_element.offsetLeft + 'px';
460 newDiv.style.height = old_element.offsetHeight + 'px';
461 newDiv.style.width = old_element.offsetWidth + 'px';
462 old_element.parentNode.insertBefore(newDiv, old_element);
463 old_element.remove();
464 newDiv.parentNode.style.overflow = 'hidden';
465  """
466  self.driverdriverdriver.execute_script(script, element)
467 
468  @keyword
469 
474  def get_value(self, locator):
475  return self.get_element_attributeget_element_attribute(locator, 'value')
476 
477  @keyword
478 
483  def get_text(self, locator):
484  return self.find_elementfind_element(locator).text
485 
486  @keyword
487 
492  def clear_element_text(self, locator):
493  self.find_elementfind_element(locator).clear()
494 
495  @keyword
496 
506  def get_vertical_position(self, locator):
507  return self.find_elementfind_element(locator).location['y']
508 
509  @keyword
510 
521  def click_button(self, locator, modifier=False):
522  if is_falsy(modifier):
523  self.infoinfo("Clicking button '%s'." % locator)
524  element = self.find_elementfind_element(locator, tag='input', required=False)
525  if not element:
526  element = self.find_elementfind_element(locator, tag='button')
527  element.click()
528  else:
529  self._click_with_modifier_click_with_modifier(locator, ['button', 'input'], modifier)
530 
531  @keyword
532 
543  def click_image(self, locator, modifier=False):
544  if is_falsy(modifier):
545  self.infoinfo("Clicking image '%s'." % locator)
546  element = self.find_elementfind_element(locator, tag='image', required=False)
547  if not element:
548  # A form may have an image as it's submit trigger.
549  element = self.find_elementfind_element(locator, tag='input')
550  element.click()
551  else:
552  self._click_with_modifier_click_with_modifier(locator, ['image', 'input'], modifier)
553 
554  @keyword
555 
566  def click_link(self, locator, modifier=False):
567  if is_falsy(modifier):
568  self.infoinfo("Clicking link '%s'." % locator)
569  self.find_elementfind_element(locator, tag='link').click()
570  else:
571  self._click_with_modifier_click_with_modifier(locator, ['link', 'link'], modifier)
572 
573  @keyword
574 
595  def click_element(self, locator, modifier=False):
596  if is_falsy(modifier):
597  self.infoinfo("Clicking element '%s'." % locator)
598  self.find_elementfind_element(locator).click()
599  else:
600  self._click_with_modifier_click_with_modifier(locator, [None, None], modifier)
601 
602  def _click_with_modifier(self, locator, tag, modifier):
603  self.infoinfo("Clicking %s '%s' with %s." % (tag if tag[0] else 'element', locator, modifier))
604  modifier = self.parse_modifierparse_modifier(modifier)
605  action = ActionChains(self.driverdriverdriver)
606  for item in modifier:
607  action.key_down(item)
608  element = self.find_elementfind_element(locator, tag=tag[0], required=False)
609  if not element:
610  element = self.find_elementfind_element(locator, tag=tag[1])
611  action.click(element)
612  for item in modifier:
613  action.key_up(item)
614  action.perform()
615 
616  @keyword
617 
625  def click_element_at_coordinates(self, locator, xoffset, yoffset):
626  self.infoinfo("Clicking element '%s' at coordinates x=%s, y=%s."
627  % (locator, xoffset, yoffset))
628  element = self.find_elementfind_element(locator)
629  action = ActionChains(self.driverdriverdriver)
630  action.move_to_element(element)
631  action.move_by_offset(xoffset, yoffset)
632  action.click()
633  action.perform()
634 
635  @keyword
636 
641  def double_click_element(self, locator):
642  self.infoinfo("Double clicking element '%s'." % locator)
643  element = self.find_elementfind_element(locator)
644  action = ActionChains(self.driverdriverdriver)
645  action.double_click(element).perform()
646 
647  @keyword
648 
655  def set_focus_to_element(self, locator):
656  element = self.find_elementfind_element(locator)
657  self.driverdriverdriver.execute_script("arguments[0].focus();", element)
658 
659  @keyword
660 
667  def scroll_element_into_view(self, locator):
668  element = self.find_elementfind_element(locator)
669  ActionChains(self.driverdriverdriver).move_to_element(element).perform()
670 
671  @keyword
672 
681  def drag_and_drop(self, locator, target):
682  element = self.find_elementfind_element(locator)
683  target = self.find_elementfind_element(target)
684  action = ActionChains(self.driverdriverdriver)
685  action.drag_and_drop(element, target).perform()
686 
687  @keyword
688 
699  def drag_and_drop_by_offset(self, locator, xoffset, yoffset):
700  element = self.find_elementfind_element(locator)
701  action = ActionChains(self.driverdriverdriver)
702  action.drag_and_drop_by_offset(element, int(xoffset), int(yoffset))
703  action.perform()
704 
705  @keyword
706 
716  def mouse_down(self, locator):
717  self.infoinfo("Simulating Mouse Down on element '%s'." % locator)
718  element = self.find_elementfind_element(locator)
719  action = ActionChains(self.driverdriverdriver)
720  action.click_and_hold(element).perform()
721 
722  @keyword
723 
728  def mouse_out(self, locator):
729  self.infoinfo("Simulating Mouse Out on element '%s'." % locator)
730  element = self.find_elementfind_element(locator)
731  size = element.size
732  offsetx = (size['width'] / 2) + 1
733  offsety = (size['height'] / 2) + 1
734  action = ActionChains(self.driverdriverdriver)
735  action.move_to_element(element).move_by_offset(offsetx, offsety)
736  action.perform()
737 
738  @keyword
739 
744  def mouse_over(self, locator):
745  self.infoinfo("Simulating Mouse Over on element '%s'." % locator)
746  element = self.find_elementfind_element(locator)
747  action = ActionChains(self.driverdriverdriver)
748  action.move_to_element(element).perform()
749 
750  @keyword
751 
756  def mouse_up(self, locator):
757  self.infoinfo("Simulating Mouse Up on element '%s'." % locator)
758  element = self.find_elementfind_element(locator)
759  ActionChains(self.driverdriverdriver).release(element).perform()
760 
761  @keyword
762 
763  def open_context_menu(self, locator):
764  element = self.find_elementfind_element(locator)
765  action = ActionChains(self.driverdriverdriver)
766  action.context_click(element).perform()
767 
768  @keyword
769 
779  def simulate_event(self, locator, event):
780  element = self.find_elementfind_element(locator)
781  script = """
782 element = arguments[0];
783 eventName = arguments[1];
784 if (document.createEventObject) { // IE
785  return element.fireEvent('on' + eventName, document.createEventObject());
786 }
787 var evt = document.createEvent("HTMLEvents");
788 evt.initEvent(eventName, true, true);
789 return !element.dispatchEvent(evt);
790  """
791  self.driverdriverdriver.execute_script(script, element, event)
792 
793  @keyword
794 
795  def press_key(self, locator, key):
796  if key.startswith('\\') and len(key) > 1:
797  key = self._map_ascii_key_code_to_key_map_ascii_key_code_to_key(int(key[1:]))
798  element = self.find_elementfind_element(locator)
799  element.send_keys(key)
800 
801  @keyword
802 
849  def press_keys(self, locator=None, *keys):
850  parsed_keys = self._parse_keys_parse_keys(*keys)
851  if is_truthy(locator):
852  self.infoinfo('Sending key(s) %s to %s element.' % (keys, locator))
853  else:
854  self.infoinfo('Sending key(s) %s to page.' % str(keys))
855  self._press_keys_press_keys(locator, parsed_keys)
856 
857  def _press_keys(self, locator, parsed_keys):
858  if is_truthy(locator):
859  element = self.find_elementfind_element(locator)
860  else:
861  element = None
862  for parsed_key in parsed_keys:
863  actions = ActionChains(self.driverdriverdriver)
864  special_keys = []
865  for key in parsed_key:
866  if self._selenium_keys_has_attr_selenium_keys_has_attr(key.original):
867  special_keys = self._press_keys_special_keys_press_keys_special_keys(actions, element, parsed_key,
868  key, special_keys)
869  else:
870  self._press_keys_normal_keys_press_keys_normal_keys(actions, element, key)
871  for special_key in special_keys:
872  self.infoinfo('Releasing special key %s.' % special_key.original)
873  actions.key_up(special_key.converted)
874  actions.perform()
875 
876  def _press_keys_normal_keys(self, actions, element, key):
877  self.infoinfo('Sending key%s %s' % (plural_or_not(key.converted), key.converted))
878  if element:
879  actions.send_keys_to_element(element, key.converted)
880  else:
881  actions.send_keys(key.converted)
882 
883  def _press_keys_special_keys(self, actions, element, parsed_key, key, special_keys):
884  if len(parsed_key) == 1 and element:
885  self.infoinfo('Pressing special key %s to element.' % key.original)
886  actions.send_keys_to_element(element, key.converted)
887  elif len(parsed_key) == 1 and not element:
888  self.infoinfo('Pressing special key %s to browser.' % key.original)
889  actions.send_keys(key.converted)
890  else:
891  self.infoinfo('Pressing special key %s down.' % key.original)
892  actions.key_down(key.converted)
893  special_keys.append(key)
894  return special_keys
895 
896  @keyword
897 
901  def get_all_links(self):
902  links = self.find_elementsfind_elements("tag=a")
903  return [link.get_attribute('id') for link in links]
904 
905  @keyword
906 
912  def mouse_down_on_link(self, locator):
913  element = self.find_elementfind_element(locator, tag='link')
914  action = ActionChains(self.driverdriverdriver)
915  action.click_and_hold(element).perform()
916 
917  @keyword
918 
927  def page_should_contain_link(self, locator, message=None, loglevel='TRACE'):
928  self.assert_page_containsassert_page_contains(locator, 'link', message, loglevel)
929 
930  @keyword
931 
940  def page_should_not_contain_link(self, locator, message=None, loglevel='TRACE'):
941  self.assert_page_not_containsassert_page_not_contains(locator, 'link', message, loglevel)
942 
943  @keyword
944 
950  def mouse_down_on_image(self, locator):
951  element = self.find_elementfind_element(locator, tag='image')
952  action = ActionChains(self.driverdriverdriver)
953  action.click_and_hold(element).perform()
954 
955  @keyword
956 
965  def page_should_contain_image(self, locator, message=None, loglevel='TRACE'):
966  self.assert_page_containsassert_page_contains(locator, 'image', message, loglevel)
967 
968  @keyword
969 
978  def page_should_not_contain_image(self, locator, message=None, loglevel='TRACE'):
979  self.assert_page_not_containsassert_page_not_contains(locator, 'image', message, loglevel)
980 
981  @keyword
982 
994  def get_element_count(self, locator):
995  return len(self.find_elementsfind_elements(locator))
996 
997  @keyword
998 
1009  def add_location_strategy(self, strategy_name, strategy_keyword, persist=False):
1010  self.element_finderelement_finderelement_finderelement_finder.register(strategy_name, strategy_keyword, persist)
1011 
1012  @keyword
1013 
1018  def remove_location_strategy(self, strategy_name):
1019  self.element_finderelement_finderelement_finderelement_finder.unregister(strategy_name)
1020 
1021  def _map_ascii_key_code_to_key(self, key_code):
1022  map = {
1023  0: Keys.NULL,
1024  8: Keys.BACK_SPACE,
1025  9: Keys.TAB,
1026  10: Keys.RETURN,
1027  13: Keys.ENTER,
1028  24: Keys.CANCEL,
1029  27: Keys.ESCAPE,
1030  32: Keys.SPACE,
1031  42: Keys.MULTIPLY,
1032  43: Keys.ADD,
1033  44: Keys.SEPARATOR,
1034  45: Keys.SUBTRACT,
1035  56: Keys.DECIMAL,
1036  57: Keys.DIVIDE,
1037  59: Keys.SEMICOLON,
1038  61: Keys.EQUALS,
1039  127: Keys.DELETE
1040  }
1041  key = map.get(key_code)
1042  if key is None:
1043  key = chr(key_code)
1044  return key
1045 
1047  try:
1048  return getattr(Keys, key_name)
1049  except AttributeError:
1050  message = "Unknown key named '%s'." % (key_name)
1051  self.debugdebug(message)
1052  raise ValueError(message)
1053 
1054  def _page_contains(self, text):
1055  self.driverdriverdriver.switch_to.default_content()
1056 
1057  if self.is_text_presentis_text_present(text):
1058  return True
1059 
1060  subframes = self.find_elementsfind_elements("xpath://frame|//iframe")
1061  self.debugdebug('Current frame has %d subframes.' % len(subframes))
1062  for frame in subframes:
1063  self.driverdriverdriver.switch_to.frame(frame)
1064  found_text = self.is_text_presentis_text_present(text)
1065  self.driverdriverdriver.switch_to.default_content()
1066  if found_text:
1067  return True
1068  return False
1069 
1070  def parse_modifier(self, modifier):
1071  modifier = modifier.upper()
1072  modifiers = modifier.split('+')
1073  keys = []
1074  for item in modifiers:
1075  item = item.strip()
1076  item = self._parse_aliases_parse_aliases(item)
1077  if hasattr(Keys, item):
1078  keys.append(getattr(Keys, item))
1079  else:
1080  raise ValueError("'%s' modifier does not match to Selenium Keys"
1081  % item)
1082  return keys
1083 
1084  def _parse_keys(self, *keys):
1085  if not keys:
1086  raise AssertionError('"keys" argument can not be empty.')
1087  list_keys = []
1088  for key in keys:
1089  separate_keys = self._separate_key_separate_key(key)
1090  separate_keys = self._convert_special_keys_convert_special_keys(separate_keys)
1091  list_keys.append(separate_keys)
1092  return list_keys
1093 
1094  def _parse_aliases(self, key):
1095  if key == 'CTRL':
1096  return 'CONTROL'
1097  if key == 'ESC':
1098  return 'ESCAPE'
1099  return key
1100 
1101  def _separate_key(self, key):
1102  one_key = ''
1103  list_keys = []
1104  for char in key:
1105  if char == '+' and one_key != '':
1106  list_keys.append(one_key)
1107  one_key = ''
1108  else:
1109  one_key += char
1110  if one_key:
1111  list_keys.append(one_key)
1112  return list_keys
1113 
1114  def _convert_special_keys(self, keys):
1115  KeysRecord = namedtuple('KeysRecord', 'converted, original')
1116  converted_keys = []
1117  for key in keys:
1118  key = self._parse_aliases_parse_aliases(key)
1119  if self._selenium_keys_has_attr_selenium_keys_has_attr(key):
1120  converted_keys.append(KeysRecord(getattr(Keys, key), key))
1121  else:
1122  converted_keys.append(KeysRecord(key, key))
1123  return converted_keys
1124 
1125  def _selenium_keys_has_attr(self, key):
1126  try:
1127  return hasattr(Keys, key)
1128  except UnicodeError: # To support Python 2 and non ascii characters.
1129  return False
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 assert_page_not_contains(self, locator, tag=None, message=None, loglevel='TRACE')
def assert_page_contains(self, locator, tag=None, message=None, loglevel='TRACE')
def add_location_strategy(self, strategy_name, strategy_keyword, persist=False)
Adds a custom location strategy.
Definition: element.py:1009
def mouse_down_on_image(self, locator)
Simulates a mouse down event on an image identified by locator.
Definition: element.py:950
def mouse_over(self, locator)
Simulates hovering mouse over the element locator.
Definition: element.py:744
def get_webelement(self, locator)
Returns the first WebElement matching the given locator.
Definition: element.py:37
def page_should_contain(self, text, loglevel='TRACE')
Verifies that current page contains text.
Definition: element.py:120
def element_should_contain(self, locator, expected, message=None, ignore_case=False)
Verifies that element locator contains text expected.
Definition: element.py:70
def clear_element_text(self, locator)
Clears the value of text entry element identified by locator.
Definition: element.py:492
def get_webelements(self, locator)
Returns list of WebElement objects matching the locator.
Definition: element.py:50
def _map_named_key_code_to_special_key(self, key_name)
Definition: element.py:1046
def page_should_not_contain_link(self, locator, message=None, loglevel='TRACE')
Verifies link identified by locator is not found from current page.
Definition: element.py:940
def element_text_should_not_be(self, locator, not_expected, message=None, ignore_case=False)
Verifies that element locator does not contain exact text not_expected.
Definition: element.py:356
def get_element_size(self, locator)
Returns width and height of element identified by locator.
Definition: element.py:431
def element_should_be_disabled(self, locator)
Verifies that element identified with locator is disabled.
Definition: element.py:238
def set_focus_to_element(self, locator)
Sets focus to element identified by locator.
Definition: element.py:655
def _click_with_modifier(self, locator, tag, modifier)
Definition: element.py:602
def simulate_event(self, locator, event)
Simulates event on element identified by locator.
Definition: element.py:779
def element_should_not_be_visible(self, locator, message=None)
Verifies that the element identified by locator is NOT visible.
Definition: element.py:300
def click_element_at_coordinates(self, locator, xoffset, yoffset)
Click element locator at xoffset/yoffset.
Definition: element.py:625
def press_key(self, locator, key)
DEPRECATED in SeleniumLibrary 4.0.
Definition: element.py:795
def remove_location_strategy(self, strategy_name)
Removes a previously added custom location strategy.
Definition: element.py:1018
def _press_keys(self, locator, parsed_keys)
Definition: element.py:857
def get_all_links(self)
Returns a list containing ids of all links found in current page.
Definition: element.py:901
def page_should_not_contain_image(self, locator, message=None, loglevel='TRACE')
Verifies image identified by locator is found from current page.
Definition: element.py:978
def open_context_menu(self, locator)
Opens context menu on element identified by locator.
Definition: element.py:763
def mouse_up(self, locator)
Simulates releasing the left mouse button on the element locator.
Definition: element.py:756
def get_element_count(self, locator)
Returns number of elements matching locator.
Definition: element.py:994
def element_should_be_visible(self, locator, message=None)
Verifies that the element identified by locator is visible.
Definition: element.py:286
def drag_and_drop_by_offset(self, locator, xoffset, yoffset)
Drags element identified with locator by xoffset/yoffset.
Definition: element.py:699
def get_text(self, locator)
Returns the text value of element identified by locator.
Definition: element.py:483
def page_should_not_contain(self, text, loglevel='TRACE')
Verifies the current page does not contain text.
Definition: element.py:190
def element_should_not_contain(self, locator, expected, message=None, ignore_case=False)
Verifies that element locator does not contains text expected.
Definition: element.py:97
def element_text_should_be(self, locator, expected, message=None, ignore_case=False)
Verifies that element locator contains exact text expected.
Definition: element.py:328
def click_image(self, locator, modifier=False)
Clicks an image identified by locator.
Definition: element.py:543
def _press_keys_normal_keys(self, actions, element, key)
Definition: element.py:876
def get_value(self, locator)
Returns the value attribute of element identified by locator.
Definition: element.py:474
def mouse_down_on_link(self, locator)
Simulates a mouse down event on a link identified by locator.
Definition: element.py:912
def get_element_attribute(self, locator, attribute)
Returns value of attribute from element locator.
Definition: element.py:383
def mouse_down(self, locator)
Simulates pressing the left mouse button on the element locator.
Definition: element.py:716
def mouse_out(self, locator)
Simulates moving mouse away from the element locator.
Definition: element.py:728
def press_keys(self, locator=None, *keys)
Simulates user pressing key(s) to an element or on the active browser.
Definition: element.py:849
def click_link(self, locator, modifier=False)
Clicks a link identified by locator.
Definition: element.py:566
def element_attribute_value_should_be(self, locator, attribute, expected, message=None)
Verifies element identified by locator contains expected attribute value.
Definition: element.py:397
def scroll_element_into_view(self, locator)
Scrolls an element identified by locator into view.
Definition: element.py:667
def page_should_contain_image(self, locator, message=None, loglevel='TRACE')
Verifies image identified by locator is found from current page.
Definition: element.py:965
def page_should_not_contain_element(self, locator, message=None, loglevel='TRACE')
Verifies that element locator is found on the current page.
Definition: element.py:206
def element_should_be_enabled(self, locator)
Verifies that element identified with locator is enabled.
Definition: element.py:251
def element_should_be_focused(self, locator)
Verifies that element identified with locator is focused.
Definition: element.py:263
def drag_and_drop(self, locator, target)
Drags element identified by locator into target element.
Definition: element.py:681
def page_should_contain_element(self, locator, message=None, loglevel='TRACE', limit=None)
Verifies that element locator is found on the current page.
Definition: element.py:153
def click_button(self, locator, modifier=False)
Clicks button identified by locator.
Definition: element.py:521
def page_should_contain_link(self, locator, message=None, loglevel='TRACE')
Verifies link identified by locator is found from current page.
Definition: element.py:927
def assign_id_to_element(self, locator, id)
Assigns temporary id to element specified by locator.
Definition: element.py:224
def click_element(self, locator, modifier=False)
Click element identified by locator.
Definition: element.py:595
def get_horizontal_position(self, locator)
Returns horizontal position of element identified by locator.
Definition: element.py:417
def get_vertical_position(self, locator)
Returns vertical position of element identified by locator.
Definition: element.py:506
def cover_element(self, locator)
Will cover elements identified by locator with a blue div without breaking page layout.
Definition: element.py:446
def double_click_element(self, locator)
Double click element identified by locator.
Definition: element.py:641
def locator_should_match_x_times(self, locator, x, message=None, loglevel='TRACE')
DEPRECATED in SeleniumLibrary 4.0.
Definition: element.py:171
def _press_keys_special_keys(self, actions, element, parsed_key, key, special_keys)
Definition: element.py:883