How to use _is_locator_format method in robotframework-pageobjects

Best Python code snippet using robotframework-pageobjects_python

base.py

Source:base.py Github

copy

Full Screen

...578 locator = self.resolve_selector(locator)579 try:580 return super(_BaseActions, self)._element_find(locator, *args, **kwargs)581 except ValueError:582 if not self._is_locator_format(locator):583 # Not found, doesn't look like a locator, not in selectors dict584 raise exceptions.SelectorError(585 "\"%s\" is not a valid locator. If this is a selector name, make sure it is spelled correctly." % locator)586 else:587 raise588 finally:589 self.driver.implicitly_wait(self.selenium_implicit_wait)590 @not_keyword591 def find_element(self, locator, required=True, wait=None, **kwargs):592 """593 Wraps Selenium2Library's protected _element_find() method to find single elements.594 TODO: Incorporate selectors API into this.595 :param locator: The Selenium2Library-style locator to use596 :type locator: str597 :param required: Optional parameter indicating whether an exception should be raised if no matches are found. Defaults to True.598 :type required: boolean599 :param wait: Maximum Time in seconds to wait until the element exists. By default the implicit wait is 10600 seconds for any element finding method, including Se2lib methods. Passing a wait to find_element overrides601 this.602 :returns: WebElement instance603 """604 ret = self._element_find(locator, first_only=False, required=required, wait=wait, **kwargs)605 if len(ret) > 1:606 raise exceptions.SelectorError(607 "\"%s\" found more than one element. If this is expected, use \"find_elements\" instead" % locator)608 return ret[0]609 @not_keyword610 def find_elements(self, locator, required=True, wait=None, **kwargs):611 """612 Wraps Selenium2Library's protected _element_find() method to find multiple elements.613 TODO: Incorporate selectors API into this.614 :param locator: The Selenium2Library-style locator to use615 :type locator: str616 :param required: Optional parameter indicating whether an exception should be raised if no matches are found. Defaults to True.617 :type required: boolean618 :param wait: Maximum Time in seconds to wait until the element exists. By default the implicit wait is 10619 seconds for any element finding method, including Se2lib methods. Passing a wait to find_element overrides620 this.621 :returns: WebElement instance622 """623 return self._element_find(locator, first_only=False, required=required, wait=wait, **kwargs)624 @not_keyword625 def get_subclass_from_po_module(self, module_name, super_class, fallback_to_super=True):626 """Given `module_name`, try to import it and find in it a subclass of627 `super_class`. This is for dynamically resolving what page object to use628 for, say, a search that can bring up multiple types of search result page.629 :param module_name: The name of the module to look for.630 :type module_name: str631 :param super_class: The class to look for subclasses of.632 :type super_class: type633 :param fallback_to_super: Whether to default to returning `super_class` if module `module_name`634 cannot be imported.635 :returns: type636 """637 try:638 po_mod = importlib.import_module(module_name)639 except ImportError:640 if fallback_to_super:641 return super_class642 else:643 for name, obj in inspect.getmembers(po_mod):644 if inspect.isclass(obj) and issubclass(obj, super_class) and obj != super_class:645 return obj646 raise exceptions.PageSelectionError("You need to have the %s package installed to go to a %s page,"647 "and the package needs to have a subclass of %s."648 % (module_name, module_name, super_class))649 def _is_locator_format(self, locator):650 """651 Ask Selenium2Library's ElementFinder if the locator uses652 one of its supported prefixes.653 :param locator: The locator to look up654 :type locator: str655 """656 finder = self._element_finder657 prefix = finder._parse_locator(locator)[0]658 return prefix is not None or locator.startswith("//")659 def location_should_be(self, expected_url):660 """661 Wrapper for Selenium2Library's location_should_be() method. Allows matching against the662 baseurl if a partial url is given.663 :param url: Either complete url or partial url to be validated against...

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-pageobjects 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