def test_can_be_cleared(self, browser): wd = browser.div().wd element = Element(browser, {'id': 'not_valid'}) element.cache = wd browser.refresh() assert element.exists is False
def test_raises_correct_exception_if_given_the_wrong_number_of_arguments( self): from nerodia.elements.element import Element with pytest.raises(TypeError): Element('container', 1, 2, 3, 4) with pytest.raises(TypeError): Element('container', 'foo')
def _matches_selector(self, element, selector): def check_match(how, what): if how == 'tag_name' and isinstance(what, six.string_types): return self.element_validator.validate(element, {'tag_name': what}) else: return Validator.match_str_or_regex( what, self._fetch_value(element, how)) matches = all(check_match(how, what) for how, what in selector.items()) text_selector = selector.get('text') if text_selector is not None: from nerodia.elements.element import Element text_content = Element(self.query_scope, {'element': element}).\ _execute_js('getTextContent', element).strip() text_content_matches = Validator.match_str_or_regex( text_selector, text_content) if matches != text_content_matches: key = 'text' if 'text' in self.selector else 'label' nerodia.logger.deprecate( 'Using {!r} locator with RegExp: {!r} to match an element ' 'that includes hidden ' 'text'.format(key, text_selector.pattern), 'visible_{}'.format(key), ids=['visible_text']) return matches
def _text_regexp_deprecation(self, element, selector, matches): from nerodia.elements.element import Element new_element = Element(self.query_scope, {'element': element}) text_content = new_element._execute_js('getTextContent', element).strip() text_selector = selector.get('text', '') text_content_matches = re.search(text_selector, text_content) is not None if matches != text_content_matches: key = 'text' if 'text' in self.selector else 'label' nerodia.logger.deprecate( 'Using {!r} locator with RegExp: {!r} to match an element ' 'that includes hidden ' 'text'.format(key, text_selector.pattern), 'visible_{}'.format(key), ids=['text_regexp'])
def _deprecate_text_regexp(self, element, selector): from nerodia.elements.element import Element new_element = Element(self.query_scope, {'element': element}) text_content = new_element.text_content if re.search(selector.get('text'), text_content) is not None: return key = 'text' if 'text' in self.selector else 'label' selector_text = selector.get('text') dep = "Using '{}' locator with RegExp {} to match an element that includes " \ "hidden text".format(key, selector_text) nerodia.logger.deprecate(dep, "'visible_{}'".format(key), ids=['text_regexp'])
def _fetch_value(self, element, how): if how == 'text': from nerodia.elements.element import Element vis = element.text all = Element(self.query_scope, {'element': element})._execute_js('getTextContent', element).strip() if all != vis.strip(): nerodia.logger.deprecate("'text' locator with RegExp values to find elements " "based on only visible text", 'visible_text') return vis elif how == 'visible_text': return element.text elif how == 'tag_name': return element.tag_name.lower() elif how == 'href': href = element.get_attribute('href') return href and href.strip() else: return element.get_attribute(how.replace('_', '-')) or ''
def test_bypasses_selector_location(self, browser): wd = browser.div().wd element = Element(browser, {'id': 'not_valid'}) element.cache = wd assert element.exists is True