Best Python code snippet using robotframework-appiumlibrary_python
_element.py
Source:_element.py
...31 """Types the given `text` into text field identified by `locator`.32 See `introduction` for details about locating elements.33 """34 self._info("Typing text '%s' into text field '%s'" % (text, locator))35 self._element_input_text_by_locator(locator, text)36 def input_password(self, locator, text):37 """Types the given password into text field identified by `locator`.38 Difference between this keyword and `Input Text` is that this keyword39 does not log the given password. See `introduction` for details about40 locating elements.41 """42 self._info("Typing password into text field '%s'" % locator)43 self._element_input_text_by_locator(locator, text)44 def input_value(self, locator, text):45 """Sets the given value into text field identified by `locator`. This is an IOS only keyword, input value makes use of set_value46 See `introduction` for details about locating elements.47 """48 self._info("Setting text '%s' into text field '%s'" % (text, locator))49 self._element_input_value_by_locator(locator, text)50 def reset_application(self):51 """ Reset application """52 driver = self._current_application()53 driver.reset()54 def hide_keyboard(self):55 """56 Hides the software keyboard on the device, using the specified key to57 press. If no key name is given, the keyboard is closed by moving focus58 from the text field. iOS only.59 """60 if not self._is_ios():61 raise EnvironmentError("Hide Keyword only support for iOS .")62 driver = self._current_application()63 driver.hide_keyboard()64 def page_should_contain_text(self, text, loglevel='INFO'):65 """Verifies that current page contains `text`.66 If this keyword fails, it automatically logs the page source67 using the log level specified with the optional `loglevel` argument.68 Giving `NONE` as level disables logging.69 """70 if not text in self.log_source(loglevel):71 self.log_source(loglevel)72 raise AssertionError("Page should have contained text '%s' "73 "but did not" % text)74 self._info("Current page contains text '%s'." % text)75 def page_should_not_contain_text(self, text, loglevel='INFO'):76 """Verifies that current page not contains `text`.77 If this keyword fails, it automatically logs the page source78 using the log level specified with the optional `loglevel` argument.79 Giving `NONE` as level disables logging.80 """81 if text in self.log_source(loglevel):82 self.log_source(loglevel)83 raise AssertionError("Page should not have contained text '%s' "84 "but did not" % text)85 self._info("Current page does not contains text '%s'." % text)86 def page_should_contain_element(self, locator, loglevel='INFO'):87 """Verifies that current page contains `locator` element.88 If this keyword fails, it automatically logs the page source89 using the log level specified with the optional `loglevel` argument.90 Givin91 """ 92 if not self._is_element_present(locator):93 self.log_source(loglevel)94 raise AssertionError("Page should have contained element '%s' "95 "but did not" % locator) 96 self._info("Current page contains element '%s'." % locator)97 def page_should_not_contain_element(self, locator, loglevel='INFO'):98 """Verifies that current page not contains `locator` element.99 If this keyword fails, it automatically logs the page source100 using the log level specified with the optional `loglevel` argument.101 Givin102 """ 103 if self._is_element_present(locator):104 self.log_source(loglevel)105 raise AssertionError("Page should not have contained element '%s' "106 "but did not" % locator) 107 self._info("Current page not contains element '%s'." % locator)108 def element_should_be_disabled(self, locator):109 """Verifies that element identified with locator is disabled.110 Key attributes for arbitrary elements are `id` and `name`. See111 `introduction` for details about locating elements. 112 """113 if self._element_find(locator, True, True).is_enabled():114 self.log_source(loglevel)115 raise AssertionError("Element '%s' should be disabled "116 "but did not" % locator) 117 self._info("Element '%s' is disabled ." % locator)118 def element_should_be_enabled(self, locator):119 """Verifies that element identified with locator is enabled.120 Key attributes for arbitrary elements are `id` and `name`. See121 `introduction` for details about locating elements. 122 """123 if not self._element_find(locator, True, True).is_enabled():124 self.log_source(loglevel)125 raise AssertionError("Element '%s' should be enabled "126 "but did not" % locator) 127 self._info("Element '%s' is enabled ." % locator)128 def element_name_should_be(self, locator, expected):129 element = self._element_find(locator, True, True)130 if expected != element.get_attribute('name'):131 raise AssertionError("Element '%s' name should be '%s' "132 "but it is '%s'." % (locator, expected, element.get_attribute('name'))) 133 self._info("Element '%s' name is '%s' " % (locator, expected))134 """135 @Author: Minh.nguyen136 @Created Date: Jan 18, 2014137 @Modified By: N/A138 @Description: 139 """140 def get_element_attribute(self, locator, attribute):141 """Get element attribute.142 """143 element = self._element_find(locator, True, True)144 return element.get_attribute(attribute)145 def get_element_text(self, locator):146 """Get element text.147 """148 element = self._element_find(locator, True, True)149 return element.get_attribute('text')150 def element_text_should_be(self, locator, expected):151 """Get current element text and compare to expected text152 """153 element = self._element_find(locator, True, True)154 current_text = element.get_attribute(attribute)155 if current_text != expected:156 raise AssertionError("Element '%s' text should be '%s' "157 "but it is '%s'." % (locator, expected, current_text)) 158 # Private159 160 def _is_index(self, index_or_name):161 if index_or_name.startswith('index='):162 return True163 else:164 return False165 def _click_element_by_name(self, name):166 driver = self._current_application()167 try:168 element = driver.find_element_by_name(name)169 except Exception, e:170 raise Exception, e171 172 try:173 element.click()174 except Exception, e:175 raise Exception, 'Cannot click the element with name "%s"' % name176 def _find_elements_by_class_name(self, class_name):177 driver = self._current_application()178 elements = driver.find_elements_by_class_name(class_name)179 return elements180 def _find_element_by_class_name(self, class_name, index_or_name):181 elements = self._find_elements_by_class_name(class_name)182 183 if self._is_index(index_or_name):184 try:185 index = int(index_or_name.split('=')[-1])186 element = elements[index]187 except IndexError, TypeError:188 raise Exception, 'Cannot find the element with index "%s"' % index_or_name189 else:190 found = False191 for element in elements:192 self._info("'%s'." % element.text)193 if element.text == index_or_name:194 found = True195 break196 if not found:197 raise Exception, 'Cannot find the element with name "%s"' % index_or_name198 return element199 def _get_class(self, platform_class_dict):200 return platform_class_dict.get(self._get_platform()) 201 def _is_support_platform(self, platform_class_dict):202 return platform_class_dict.has_key(self._get_platform())203 def _click_element_by_class_name(self, class_name, index_or_name):204 element = self._find_element_by_class_name(class_name, index_or_name)205 self._info("Clicking element '%s'." % element.text)206 try:207 element.click()208 except Exception, e:209 raise Exception, 'Cannot click the %s element "%s"' % (class_name, index_or_name)210 def _element_clear_text_by_locator(self, locator):211 try:212 element = self._element_find(locator, True, True)213 element.clear()214 except Exception, e:215 raise e216 def _element_input_text_by_locator(self, locator, text):217 try:218 element = self._element_find(locator, True, True)219 element.send_keys(text)220 except Exception, e:221 raise e222 def _element_input_text_by_class_name(self, class_name, index_or_name, text):223 try:224 element = self._find_element_by_class_name(class_name, index_or_name)225 except Exception, e:226 raise Exception, e227 self._info("input text in element as '%s'." % element.text)228 try:229 element.send_keys(text)230 except Exception, e:...
common.py
Source:common.py
...58 See `introduction` for details about locating elements.59 """60 appiumlib = BuiltIn().get_library_instance('SongzAppiumLibrary')61 appiumlib._info("Typing text '%s' into text field '%s'" % (text, locator))62 appiumlib._element_input_text_by_locator(locator, text)63# *********************Others***************************64 def login(self,user,password,captcha):65 driver = webdriver.Chrome()66 driver.get('http://betanewwsh.vikduo.com/login/index')67 driver.find_element_by_id('staff_id').send_keys(user)68 driver.find_element_by_id('password').send_keys(password)69 driver.find_element_by_id('captcha').send_keys(captcha)70 driver.find_element_by_id('login').click()71 time.sleep(3)72 driver.find_element_by_id('navbar').click()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!