How to use _get_tag_and_constraints method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

elementfinder.py

Source:elementfinder.py Github

copy

Full Screen

...17 (prefix, criteria) = self._parse_locator(locator)18 strategy = self._strategies.get(prefix)19 if strategy is None:20 raise ValueError("Element locator with prefix '" + prefix + "' is not supported")21 (tag, constraints) = self._get_tag_and_constraints(tag)22 return strategy(browser, criteria, tag, constraints)23 # Strategy routines, private24 def _find_by_identifier(self, browser, criteria, tag, constraints):25 elements = browser.find_elements_by_id(criteria)26 elements.extend(browser.find_elements_by_name(criteria))27 return self._filter_elements(elements, tag, constraints)28 def _find_by_id(self, browser, criteria, tag, constraints):29 return self._filter_elements(30 browser.find_elements_by_id(criteria),31 tag, constraints)32 def _find_by_name(self, browser, criteria, tag, constraints):33 return self._filter_elements(34 browser.find_elements_by_name(criteria),35 tag, constraints)36 def _find_by_xpath(self, browser, criteria, tag, constraints):37 return self._filter_elements(38 browser.find_elements_by_xpath(criteria),39 tag, constraints)40 def _find_by_link_text(self, browser, criteria, tag, constraints):41 return self._filter_elements(42 browser.find_elements_by_link_text(criteria),43 tag, constraints)44 def _find_by_css_selector(self, browser, criteria, tag, constraints):45 return self._filter_elements(46 browser.find_elements_by_css_selector(criteria),47 tag, constraints)48 def _find_by_tag_name(self, browser, criteria, tag, constraints):49 return self._filter_elements(50 browser.find_elements_by_tag_name(criteria),51 tag, constraints)52 def _find_by_default(self, browser, criteria, tag, constraints):53 if criteria.startswith('//'):54 return self._find_by_xpath(browser, criteria, tag, constraints)55 return self._find_by_key_attrs(browser, criteria, tag, constraints)56 def _find_by_key_attrs(self, browser, criteria, tag, constraints):57 key_attrs = self._key_attrs.get(None)58 if tag is not None:59 key_attrs = self._key_attrs.get(tag, key_attrs)60 xpath_criteria = utils.escape_xpath_value(criteria)61 xpath_tag = tag if tag is not None else '*'62 xpath_constraints = ["@%s='%s'" % (name, constraints[name]) for name in constraints]63 xpath_searchers = ["%s=%s" % (attr, xpath_criteria) for attr in key_attrs]64 xpath_searchers.extend(65 self._get_attrs_with_url(key_attrs, criteria, browser))66 xpath = "//%s[%s(%s)]" % (67 xpath_tag,68 ' and '.join(xpath_constraints) + ' and ' if len(xpath_constraints) > 0 else '',69 ' or '.join(xpath_searchers))70 return browser.find_elements_by_xpath(xpath)71 # Private72 _key_attrs = {73 None: ['@id', '@name'],74 'a': ['@id', '@name', '@href', 'normalize-space(descendant-or-self::text())'],75 'img': ['@id', '@name', '@src', '@alt'],76 'input': ['@id', '@name', '@value', '@src'],77 'button': ['@id', '@name', '@value', 'normalize-space(descendant-or-self::text())']78 }79 def _get_tag_and_constraints(self, tag):80 if tag is None: return None, {}81 tag = tag.lower()82 constraints = {}83 if tag == 'link':84 tag = 'a'85 elif tag == 'image':86 tag = 'img'87 elif tag == 'list':88 tag = 'select'89 elif tag == 'radio button':90 tag = 'input'91 constraints['type'] = 'radio'92 elif tag == 'checkbox':93 tag = 'input'...

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