def find_by_text(self, text): xpath_str = _concat_xpath_from_str(text) return self.find_by_xpath( xpath_str, original_find="text", original_query=text, )
def find_by_text(self, text=None, wait_time=None): xpath_str = _concat_xpath_from_str(text) return self.find_by_xpath( xpath_str, original_find="text", original_query=text, wait_time=wait_time, )
def find_by_text(self, text): # Add a period to the xpath to search only inside the parent. xpath_str = '.{}'.format(_concat_xpath_from_str(text)) return self.find_by_xpath( xpath_str, original_find="text", original_query=text, )
def test_build_xpath_concat_normal(): """Given a string with no escape characters When I build a concat xpath Then the xpath string is correctly built """ result = _concat_xpath_from_str('No quotation marks.') expected = "{}'No quotation marks.', \"\")]".format(XPATH_START) assert result == expected
def find_by_text(self, text, wait_time=None): # Add a period to the xpath to search only inside the parent. xpath_str = '.{}'.format(_concat_xpath_from_str(text)) return self.find_by( self._element.find_elements_by_xpath, xpath_str, original_find="text", original_query=text, wait_time=wait_time, )
def test_build_xpath_concat_nested(): """Given a string with double quotes around a single quote When I build a concat xpath Then the xpath string is correctly built """ result = _concat_xpath_from_str('A "real ol\' mess" of text.') expected = "{}\'A \',{},\"real ol\",{},\" mess\",{},\' of text.\', \"\")]".format( XPATH_START, WRAPPED_DOUBLE_QUOTE, WRAPPED_SINGLE_QUOTE, WRAPPED_DOUBLE_QUOTE, ) assert result == expected
def test_build_xpath_concat_multiple_types(): """Given a string with double quotes and single quotes When I build a concat xpath Then the xpath string is correctly built """ result = _concat_xpath_from_str('Text with a single \' quotation mark and double " quotation mark.') expected = "{}\"Text with a single \",{},\" quotation mark and double \",{},\' quotation mark.\', \"\")]".format( XPATH_START, WRAPPED_SINGLE_QUOTE, WRAPPED_DOUBLE_QUOTE, ) assert result == expected
def test_build_xpath_concat_double_quote(): """Given a string with double quotes When I build a concat xpath Then the xpath string is correctly built """ result = _concat_xpath_from_str('Denis \"Snake\" Bélanger') expected = "{}'Denis ',{},'Snake',{},' Bélanger', \"\")]".format( XPATH_START, WRAPPED_DOUBLE_QUOTE, WRAPPED_DOUBLE_QUOTE, ) assert result == expected
def find_by_text(self, text, wait_time=None): # Add a period to the xpath to search only inside the parent. xpath_str = '.{}'.format(_concat_xpath_from_str(text)) return self.find_by( self._element.find_elements, finder_kwargs={ 'by': By.XPATH, 'value': xpath_str }, original_find="text", original_query=text, wait_time=wait_time, )