How to use element_by_its method in Selene

Best Python code snippet using selene_python

entity.py

Source:entity.py Github

copy

Full Screen

...866 .filtered_by_their(lambda it: have.text(text)(it.element('.result-title')))\867 .should(have.size(3))868 OR with PageObject:869 THEN::870 results.element_by_its(lambda it: Result(it).title, have.text(text))\871 .should(have.size(3))872 Shortcut for::873 results.element_by(lambda it: have.text(text)(Result(it).title))\874 .should(have.size(3))875 WHERE::876 results = browser.all('.result')877 class Result:878 def __init__(self, element):879 self.element = element880 self.title = self.element.element('.result-title')881 self.url = self.element.element('.result-url')882 # ...883 """884 warnings.warn(885 'filtered_by_their is experimental; might be renamed or removed in future',886 FutureWarning,887 )888 def find_in(parent: Element):889 if callable(selector_or_callable):890 return selector_or_callable(parent)891 else:892 return parent.element(selector_or_callable)893 return self.filtered_by(lambda it: condition(find_in(it)))894 def element_by(895 self, condition: Union[Condition[Element], Callable[[E], None]]896 ) -> Element:897 # todo: In the implementation below...898 # We use condition in context of "matching", i.e. as a predicate...899 # why then not accept Callable[[E], bool] also?900 # (as you remember, Condition is Callable[[E], None] throwing Error)901 # This will allow the following code be possible902 # results.element_by(lambda it:903 # Result(it).title.matching(have.text(text)))904 # instead of:905 # results.element_by(lambda it: have.text(text)(906 # Result(it).title))907 # in addition to:908 # results.element_by_its(lambda it:909 # Result(it).title, have.text(text))910 # Open Points:911 # - do we need element_by_its, if we allow Callable[[E], bool] ?912 # - if we add elements_by_its, do we need then to accept Callable[[E], bool] ?913 # - probably... Callable[[E], bool] will lead to worse error messages,914 # in such case we ignore thrown error's message915 # - hm... ut seems like we nevertheless ignore it...916 # we use element.matching(condition) below917 condition = (918 condition919 if isinstance(condition, Condition)920 else Condition(str(condition), condition)921 )922 def find() -> WebElement:923 cached = self.cached924 for element in cached:925 if element.matching(condition):926 return element()927 from selene.core import query928 if self.config.log_outer_html_on_failure:929 """930 todo: move it support.shared.config931 """932 outer_htmls = [query.outer_html(element) for element in cached]933 raise AssertionError(934 f'\n\tCannot find element by condition «{condition}» '935 f'\n\tAmong {self}'936 f'\n\tActual webelements collection:'937 f'\n\t{outer_htmls}'938 ) # todo: isn't it better to print it all the time via hook, like for Element?939 else:940 raise AssertionError(941 f'\n\tCannot find element by condition «{condition}» '942 f'\n\tAmong {self}'943 )944 return Element(945 Locator(f'{self}.element_by({condition})', find), self.config946 )947 def element_by_its(948 self,949 selector_or_callable: Union[str, tuple, Callable[[Element], Element]],950 condition: Condition[Element],951 ) -> Element:952 """953 :param selector_or_callable:954 - selector may be a str with css/xpath selector or tuple with by.* locator955 - callable should be a function on element that returns element956 :param condition: a condition to957 :return: element from collection that has inner/relative element matching condition958 GIVEN html elements somewhere in DOM::959 .result960 .result-title961 .result-url962 .result-snippet963 THEN::964 browser.all('.result')\965 .element_by_its('.result-title', have.text(text))\966 .element('.result-url').click()967 ... is a shortcut for::968 browser.all('.result')\969 .element_by(lambda it: have.text(text)(it.element('.result-title')))\970 .element('.result-url').click()971 OR with PageObject:972 THEN::973 Result(results.element_by_its(lambda it: Result(it).title, have.text(text)))\974 .url.click()975 Shortcut for::976 Result(results.element_by(lambda it: have.text(text)(Result(it).title)))\977 .url.click()978 WHERE::979 results = browser.all('.result')980 class Result:981 def __init__(self, element):982 self.element = element983 self.title = self.element.element('.result-title')984 self.url = self.element.element('.result-url')985 # ...986 """987 # todo: main questions to answer before removing warning:...

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