How to use _find_element_by_class_name method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

_element.py

Source:_element.py Github

copy

Full Screen

...176 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:231 raise Exception, 'Cannot input text "%s" for the %s element "%s"' % (text, class_name, index_or_name)232 def _element_input_value_by_locator(self, locator, text):233 try:234 element = self._element_find(locator, True, True)235 element.set_value(text)236 except Exception, e:237 raise e238 def _element_find(self, locator, first_only, required, tag=None):...

Full Screen

Full Screen

google_page.py

Source:google_page.py Github

copy

Full Screen

...49 Logger.info(self, 'No results')50 return []51 @except_to_bool(exc=NoSuchElementException)52 def _is_single_result(self):53 self._find_element_by_class_name('LrzXr')54 @except_to_bool(exc=NoSuchElementException)55 def _are_multiple_results(self):56 self._find_element_by_class_name('H93uF')57 def _get_single_result(self):58 Logger.info(self, 'Getting single result...')59 result = []60 try:61 name_output_xpath = '//div[@class="SPZz6b"]//span'62 self._wait_for_element_by_xpath(name_output_xpath, timeout=2)63 name_output = self._find_element_by_xpath(name_output_xpath)64 name = name_output.text65 address_output_class = 'LrzXr'66 self._wait_for_element_by_class_name(address_output_class, timeout=2)67 address_output = self._find_element_by_class_name(address_output_class)68 address = address_output.text69 Logger.debug(self, 'Single result: {} {}'.format(name, address))70 result.append(name + '\n' + self._format_address(address) + '\n')71 except (TimeoutException,72 NoSuchElementException,73 ElementClickInterceptedException,74 StaleElementReferenceException) as e:75 Logger.error(self, e, self._get_single_result.__name__)76 raise GooglePageException('Failed to get single result')77 return result78 def _get_multiple_results(self):79 Logger.info(self, 'Getting multiple results...')80 results = []81 result_link_class = 'dbg0pd'82 try:83 self._open_map()84 self._wait_for_element_by_class_name(result_link_class, 2)85 result_links = self._find_elements_by_class_name(result_link_class)86 except (TimeoutException, NoSuchElementException, GooglePageException) as e:87 Logger.error(self, e, self._get_multiple_results.__name__)88 return results89 for result_link in result_links:90 try:91 name, address = self._get_one_of_multiple_results(result_link)92 results.append(name + '\n' + self._format_address(address) + '\n')93 except GooglePageException as e:94 Logger.error(self, e, self._get_multiple_results.__name__)95 return results96 def _open_map(self):97 try:98 map_link = self._find_element_by_class_name('H93uF')99 map_link.click()100 except (TimeoutException, ElementClickInterceptedException) as e:101 Logger.error(self, e, self._open_map.__name__)102 raise GooglePageException('Failed to open a map')103 def _get_one_of_multiple_results(self, result_link):104 try:105 result_link.click()106 sleep(2)107 name_output_xpath = '//div[@class="SPZz6b"]//span'108 self._wait_for_element_by_xpath(name_output_xpath, timeout=2)109 name_output = self._find_element_by_xpath(name_output_xpath)110 name = name_output.text111 address_output_class = 'LrzXr'112 self._wait_for_element_by_class_name(address_output_class, timeout=1)113 address_output = self._find_element_by_class_name(address_output_class)114 address = address_output.text115 except (TimeoutException,116 NoSuchElementException,117 ElementClickInterceptedException,118 StaleElementReferenceException) as e:119 Logger.error(self, e, self._get_one_of_multiple_results.__name__)120 raise GooglePageException('Failed to get one of multiple results')121 Logger.debug(self, 'One of multiple results: {} {}'.format(name, address))122 return name, address123 @staticmethod124 def _format_address(address):...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run robotframework-appiumlibrary automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful