How to use _find_web_element method in toolium

Best Python code snippet using toolium_python

page_element.py

Source:page_element.py Github

copy

Full Screen

...26 self._web_element = None27 @property28 def web_element(self):29 try:30 self._find_web_element()31 except NoSuchElementException as exception:32 parent_msg = " and parent locator '{}'".format(self.parent) if self.parent else ''33 msg = "Page element of type '%s' with locator %s%s not found"34 self.logger.error(msg, type(self).__name__, self.locator, parent_msg)35 exception.msg += "\n {}".format(msg % (type(self).__name__, self.locator, parent_msg))36 raise exception37 return self._web_element38 def _find_web_element(self):39 if not self._web_element or not self.config.getboolean_optional('Driver', 'save_web_element'):40 # If the element is encapsulated we use the shadowroot tag in yaml (eg. Shadowroot: root_element_name)41 if self.shadowroot:42 if self.locator[0] != By.CSS_SELECTOR:43 raise Exception('Locator type should be CSS_SELECTOR using shadowroot but found: '44 '%s'.format(self.locator[0]))45 # querySelector only support CSS SELECTOR locator46 self._web_element = self.driver.execute_script('return document.querySelector("%s").shadowRoot.'47 'querySelector("%s")' % (self.shadowroot,48 self.locator[1]))49 else:50 # Element will be finded from parent element or from driver51 base = self.utils.get_web_element(self.parent) if self.parent else self.driver52 if isinstance(self.locator, tuple):53 self._web_element = self.find_element(base, self.locator[0], self.locator[1])54 elif isinstance(self.locator, list):55 locators = self.locator.copy()56 for index, locator in enumerate(locators):57 # Find elements and get the correct index or find a single element58 try:59 selected_element = self.find_element(base, locator[0], locator[1])60 if isinstance(selected_element, WebElement):61 self.found_element = True62 self._web_element = selected_element63 # When the first valid locator is found we must set again the locator attribute64 # in order to be used in future methods like wait_until,65 # otherwise the execution duration will be longer.66 self.locator = (locator[0], locator[1])67 break68 except NoSuchElementException as exception:69 if index == len(locators) - 1 and not self.found_element:70 exception.msg = f"No such element: Unable to locate" \71 f" element/s with locators and elements {self.locator}"72 self.locator = (locator[0], locator[1])73 self._web_element = exception74 raise exception75 def scroll_element_into_view(self):76 x = self.web_element.location['x']77 y = self.web_element.location['y']78 self.driver.execute_script('window.scrollTo({0}, {1})'.format(x, y))79 return self80 def is_present(self):81 try:82 self._web_element = None83 self._find_web_element()84 return True85 except NoSuchElementException:86 return False87 def is_visible(self):88 return self.is_present() and self.web_element.is_displayed()89 def wait_until_visible(self, timeout=None):90 try:91 self.utils.wait_until_element_visible(self, timeout)92 except TimeoutException as exception:93 parent_msg = " and parent locator '{}'".format(self.parent) if self.parent else ''94 msg = "Page element of type '%s' with locator %s%s not found or is not visible after %s seconds"95 timeout = timeout if timeout else self.utils.get_explicitly_wait()96 self.logger.error(msg, type(self).__name__, self.locator, parent_msg, timeout)97 exception.msg += "\n {}".format(msg % (type(self).__name__, self.locator, parent_msg, timeout))...

Full Screen

Full Screen

Find.py

Source:Find.py Github

copy

Full Screen

...32 element.wait_for().exist()33 return element34 except Exception as e:35 raise Exception("Cannot find element by [%s] under:\n%s\n" % (value, self))36 def _find_web_element(self, by, value):37 '''38 Find web element, there's no intelligent wait here.39 :param by: By40 :param value: The value of different type selector41 :return:Web element which is found.42 '''43 from .WebElement.StaticElement import StaticElement44 try:45 try:46 self._selenium_context().find_element(by, value)47 return StaticElement(self, by, value)48 except Exception as handleRetry:49 self._refresh()50 self._selenium_context().find_element(by, value)...

Full Screen

Full Screen

base_page.py

Source:base_page.py Github

copy

Full Screen

...36 element._locator = self37 return element38 def get_web_elements(self):39 return self.driver.find_elements(*self)40 def _find_web_element(orig_func):41 @wraps(orig_func)42 def wrapper(self, *args):43 if type(self) is Control:44 self = self.get_web_element()45 return orig_func(self, *args)46 return wrapper47 @_find_web_element48 def set_text(self, value):49 """50 type text in input box51 :param: Text to be Enter52 :return: webElement53 """54 self.clear()...

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