Path: blob/trunk/py/selenium/webdriver/support/expected_conditions.py
1864 views
# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.1617import re18from collections.abc import Iterable19from typing import Any, Callable, Literal, TypeVar, Union2021from selenium.common.exceptions import (22NoAlertPresentException,23NoSuchElementException,24NoSuchFrameException,25StaleElementReferenceException,26WebDriverException,27)28from selenium.webdriver.common.alert import Alert29from selenium.webdriver.remote.webdriver import WebDriver, WebElement3031"""32* Canned "Expected Conditions" which are generally useful within webdriver33* tests.34"""3536D = TypeVar("D")37T = TypeVar("T")3839WebDriverOrWebElement = Union[WebDriver, WebElement]404142def title_is(title: str) -> Callable[[WebDriver], bool]:43"""An expectation for checking the title of a page.4445Parameters:46-----------47title : str48The expected title, which must be an exact match.4950Returns:51-------52boolean : True if the title matches, False otherwise.53"""5455def _predicate(driver: WebDriver):56return driver.title == title5758return _predicate596061def title_contains(title: str) -> Callable[[WebDriver], bool]:62"""An expectation for checking that the title contains a case-sensitive63substring.6465Parameters:66-----------67title : str68The fragment of title expected.6970Returns:71-------72boolean : True when the title matches, False otherwise.73"""7475def _predicate(driver: WebDriver):76return title in driver.title7778return _predicate798081def presence_of_element_located(locator: tuple[str, str]) -> Callable[[WebDriverOrWebElement], WebElement]:82"""An expectation for checking that an element is present on the DOM of a83page. This does not necessarily mean that the element is visible.8485Parameters:86-----------87locator : Tuple[str, str]88Used to find the element.8990Returns:91-------92WebElement : The WebElement once it is located.9394Example:95--------96>>> from selenium.webdriver.common.by import By97>>> from selenium.webdriver.support.ui import WebDriverWait98>>> from selenium.webdriver.support import expected_conditions as EC99>>> element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.NAME, "q")))100"""101102def _predicate(driver: WebDriverOrWebElement):103return driver.find_element(*locator)104105return _predicate106107108def url_contains(url: str) -> Callable[[WebDriver], bool]:109"""An expectation for checking that the current url contains a case-110sensitive substring.111112Parameters:113-----------114url : str115The fragment of url expected.116117Returns:118-------119boolean : True when the url matches, False otherwise.120"""121122def _predicate(driver: WebDriver):123return url in driver.current_url124125return _predicate126127128def url_matches(pattern: str) -> Callable[[WebDriver], bool]:129"""An expectation for checking the current url.130131Parameters:132-----------133pattern : str134The pattern to match with the current url.135136Returns:137-------138boolean : True when the pattern matches, False otherwise.139140Notes:141------142More powerful than url_contains, as it allows for regular expressions.143"""144145def _predicate(driver: WebDriver):146return re.search(pattern, driver.current_url) is not None147148return _predicate149150151def url_to_be(url: str) -> Callable[[WebDriver], bool]:152"""An expectation for checking the current url.153154Parameters:155-----------156url : str157The expected url, which must be an exact match.158159Returns:160-------161boolean : True when the url matches, False otherwise.162"""163164def _predicate(driver: WebDriver):165return url == driver.current_url166167return _predicate168169170def url_changes(url: str) -> Callable[[WebDriver], bool]:171"""An expectation for checking the current url is different than a given172string.173174Parameters:175-----------176url : str177The expected url, which must not be an exact match.178179Returns:180-------181boolean : True when the url does not match, False otherwise182"""183184def _predicate(driver: WebDriver):185return url != driver.current_url186187return _predicate188189190def visibility_of_element_located(191locator: tuple[str, str],192) -> Callable[[WebDriverOrWebElement], Union[Literal[False], WebElement]]:193"""An expectation for checking that an element is present on the DOM of a194page and visible. Visibility means that the element is not only displayed195but also has a height and width that is greater than 0.196197Parameters:198-----------199locator : Tuple[str, str]200Used to find the element.201202Returns:203-------204WebElement : The WebElement once it is located and visible.205206Example:207--------208>>> from selenium.webdriver.common.by import By209>>> from selenium.webdriver.support.ui import WebDriverWait210>>> from selenium.webdriver.support import expected_conditions as EC211>>> element = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.NAME, "q")))212"""213214def _predicate(driver: WebDriverOrWebElement):215try:216return _element_if_visible(driver.find_element(*locator))217except StaleElementReferenceException:218return False219220return _predicate221222223def visibility_of(element: WebElement) -> Callable[[Any], Union[Literal[False], WebElement]]:224"""An expectation for checking that an element, known to be present on the225DOM of a page, is visible.226227Parameters:228-----------229element : WebElement230The WebElement to check.231232Returns:233-------234WebElement : The WebElement once it is visible.235236Example:237--------238>>> from selenium.webdriver.common.by import By239>>> from selenium.webdriver.support.ui import WebDriverWait240>>> from selenium.webdriver.support import expected_conditions as EC241>>> element = WebDriverWait(driver, 10).until(EC.visibility_of(driver.find_element(By.NAME, "q")))242243Notes:244------245Visibility means that the element is not only displayed but also has246a height and width that is greater than 0. element is the WebElement247returns the (same) WebElement once it is visible248"""249250def _predicate(_):251return _element_if_visible(element)252253return _predicate254255256def _element_if_visible(element: WebElement, visibility: bool = True) -> Union[Literal[False], WebElement]:257"""An expectation for checking that an element, known to be present on the258DOM of a page, is of the expected visibility.259260Parameters:261-----------262element : WebElement263The WebElement to check.264visibility : bool265The expected visibility of the element.266267Returns:268-------269WebElement : The WebElement once it is visible or not visible.270"""271return element if element.is_displayed() == visibility else False272273274def presence_of_all_elements_located(locator: tuple[str, str]) -> Callable[[WebDriverOrWebElement], list[WebElement]]:275"""An expectation for checking that there is at least one element present276on a web page.277278Parameters:279-----------280locator : Tuple[str, str]281Used to find the element.282283Returns:284-------285List[WebElement] : The list of WebElements once they are located.286287Example:288--------289>>> from selenium.webdriver.common.by import By290>>> from selenium.webdriver.support.ui import WebDriverWait291>>> from selenium.webdriver.support import expected_conditions as EC292>>> elements = WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.CLASS_NAME, "foo")))293"""294295def _predicate(driver: WebDriverOrWebElement):296return driver.find_elements(*locator)297298return _predicate299300301def visibility_of_any_elements_located(locator: tuple[str, str]) -> Callable[[WebDriverOrWebElement], list[WebElement]]:302"""An expectation for checking that there is at least one element visible303on a web page.304305Parameters:306-----------307locator : Tuple[str, str]308Used to find the element.309310Returns:311-------312List[WebElement] : The list of WebElements once they are located and visible.313314Example:315--------316>>> from selenium.webdriver.common.by import By317>>> from selenium.webdriver.support.ui import WebDriverWait318>>> from selenium.webdriver.support import expected_conditions as EC319>>> elements = WebDriverWait(driver, 10).until(EC.visibility_of_any_elements_located((By.CLASS_NAME, "foo")))320"""321322def _predicate(driver: WebDriverOrWebElement):323return [element for element in driver.find_elements(*locator) if _element_if_visible(element)]324325return _predicate326327328def visibility_of_all_elements_located(329locator: tuple[str, str],330) -> Callable[[WebDriverOrWebElement], Union[list[WebElement], Literal[False]]]:331"""An expectation for checking that all elements are present on the DOM of332a page and visible. Visibility means that the elements are not only333displayed but also has a height and width that is greater than 0.334335Parameters:336-----------337locator : Tuple[str, str]338Used to find the elements.339340Returns:341-------342List[WebElement] : The list of WebElements once they are located and visible.343344Example:345--------346>>> from selenium.webdriver.common.by import By347>>> from selenium.webdriver.support.ui import WebDriverWait348>>> from selenium.webdriver.support import expected_conditions as EC349>>> elements = WebDriverWait(driver, 10).until(EC.visibility_of_all_elements_located((By.CLASS_NAME, "foo")))350"""351352def _predicate(driver: WebDriverOrWebElement):353try:354elements = driver.find_elements(*locator)355for element in elements:356if _element_if_visible(element, visibility=False):357return False358return elements359except StaleElementReferenceException:360return False361362return _predicate363364365def text_to_be_present_in_element(locator: tuple[str, str], text_: str) -> Callable[[WebDriverOrWebElement], bool]:366"""An expectation for checking if the given text is present in the367specified element.368369Parameters:370-----------371locator : Tuple[str, str]372Used to find the element.373text_ : str374The text to be present in the element.375376Returns:377-------378boolean : True when the text is present, False otherwise.379380Example:381--------382>>> from selenium.webdriver.common.by import By383>>> from selenium.webdriver.support.ui import WebDriverWait384>>> from selenium.webdriver.support import expected_conditions as EC385>>> is_text_in_element = WebDriverWait(driver, 10).until(386EC.text_to_be_present_in_element((By.CLASS_NAME, "foo"), "bar")387)388"""389390def _predicate(driver: WebDriverOrWebElement):391try:392element_text = driver.find_element(*locator).text393return text_ in element_text394except StaleElementReferenceException:395return False396397return _predicate398399400def text_to_be_present_in_element_value(401locator: tuple[str, str], text_: str402) -> Callable[[WebDriverOrWebElement], bool]:403"""An expectation for checking if the given text is present in the404element's value.405406Parameters:407-----------408locator : Tuple[str, str]409Used to find the element.410text_ : str411The text to be present in the element's value.412413Returns:414-------415boolean : True when the text is present, False otherwise.416417Example:418--------419>>> from selenium.webdriver.common.by import By420>>> from selenium.webdriver.support.ui import WebDriverWait421>>> from selenium.webdriver.support import expected_conditions as EC422>>> is_text_in_element_value = WebDriverWait(driver, 10).until(423... EC.text_to_be_present_in_element_value((By.CLASS_NAME, "foo"), "bar")424... )425"""426427def _predicate(driver: WebDriverOrWebElement):428try:429element_text = driver.find_element(*locator).get_attribute("value")430if element_text is None:431return False432return text_ in element_text433except StaleElementReferenceException:434return False435436return _predicate437438439def text_to_be_present_in_element_attribute(440locator: tuple[str, str], attribute_: str, text_: str441) -> Callable[[WebDriverOrWebElement], bool]:442"""An expectation for checking if the given text is present in the443element's attribute.444445Parameters:446-----------447locator : Tuple[str, str]448Used to find the element.449attribute_ : str450The attribute to check the text in.451text_ : str452The text to be present in the element's attribute.453454Returns:455-------456boolean : True when the text is present, False otherwise.457458Example:459--------460>>> from selenium.webdriver.common.by import By461>>> from selenium.webdriver.support.ui import WebDriverWait462>>> from selenium.webdriver.support import expected_conditions as EC463>>> is_text_in_element_attribute = WebDriverWait(driver, 10).until(464... EC.text_to_be_present_in_element_attribute((By.CLASS_NAME, "foo"), "bar", "baz")465... )466"""467468def _predicate(driver: WebDriverOrWebElement):469try:470element_text = driver.find_element(*locator).get_attribute(attribute_)471if element_text is None:472return False473return text_ in element_text474except StaleElementReferenceException:475return False476477return _predicate478479480def frame_to_be_available_and_switch_to_it(481locator: Union[tuple[str, str], str, WebElement],482) -> Callable[[WebDriver], bool]:483"""An expectation for checking whether the given frame is available to484switch to.485486Parameters:487-----------488locator : Union[Tuple[str, str], str, WebElement]489Used to find the frame.490491Returns:492-------493boolean : True when the frame is available, False otherwise.494495Example:496--------497>>> from selenium.webdriver.support.ui import WebDriverWait498>>> from selenium.webdriver.support import expected_conditions as EC499>>> WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it("frame_name"))500501Notes:502------503If the frame is available it switches the given driver to the504specified frame.505"""506507def _predicate(driver: WebDriver):508try:509if isinstance(locator, Iterable) and not isinstance(locator, str):510driver.switch_to.frame(driver.find_element(*locator))511else:512driver.switch_to.frame(locator)513return True514except NoSuchFrameException:515return False516517return _predicate518519520def invisibility_of_element_located(521locator: Union[WebElement, tuple[str, str]],522) -> Callable[[WebDriverOrWebElement], Union[WebElement, bool]]:523"""An Expectation for checking that an element is either invisible or not524present on the DOM.525526Parameters:527-----------528locator : Union[WebElement, Tuple[str, str]]529Used to find the element.530531Returns:532-------533boolean : True when the element is invisible or not present, False otherwise.534535Example:536--------537>>> from selenium.webdriver.common.by import By538>>> from selenium.webdriver.support.ui import WebDriverWait539>>> from selenium.webdriver.support import expected_conditions as EC540>>> is_invisible = WebDriverWait(driver, 10).until(EC.invisibility_of_element_located((By.CLASS_NAME, "foo")))541542Notes:543------544- In the case of NoSuchElement, returns true because the element is not545present in DOM. The try block checks if the element is present but is546invisible.547- In the case of StaleElementReference, returns true because stale element548reference implies that element is no longer visible.549"""550551def _predicate(driver: WebDriverOrWebElement):552try:553target = locator554if not isinstance(target, WebElement):555target = driver.find_element(*target)556return _element_if_visible(target, visibility=False)557except (NoSuchElementException, StaleElementReferenceException):558# In the case of NoSuchElement, returns true because the element is559# not present in DOM. The try block checks if the element is present560# but is invisible.561# In the case of StaleElementReference, returns true because stale562# element reference implies that element is no longer visible.563return True564565return _predicate566567568def invisibility_of_element(569element: Union[WebElement, tuple[str, str]],570) -> Callable[[WebDriverOrWebElement], Union[WebElement, bool]]:571"""An Expectation for checking that an element is either invisible or not572present on the DOM.573574Parameters:575-----------576element : Union[WebElement, Tuple[str, str]]577Used to find the element.578579Returns:580-------581boolean : True when the element is invisible or not present, False otherwise.582583Example:584--------585>>> from selenium.webdriver.common.by import By586>>> from selenium.webdriver.support.ui import WebDriverWait587>>> from selenium.webdriver.support import expected_conditions as EC588>>> is_invisible_or_not_present = WebDriverWait(driver, 10).until(589... EC.invisibility_of_element(driver.find_element(By.CLASS_NAME, "foo"))590... )591"""592return invisibility_of_element_located(element)593594595def element_to_be_clickable(596mark: Union[WebElement, tuple[str, str]],597) -> Callable[[WebDriverOrWebElement], Union[Literal[False], WebElement]]:598"""An Expectation for checking an element is visible and enabled such that599you can click it.600601Parameters:602-----------603mark : Union[WebElement, Tuple[str, str]]604Used to find the element.605606Returns:607-------608WebElement : The WebElement once it is located and clickable.609610Example:611--------612>>> from selenium.webdriver.common.by import By613>>> from selenium.webdriver.support.ui import WebDriverWait614>>> from selenium.webdriver.support import expected_conditions as EC615>>> element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, "foo")))616"""617618# renamed argument to 'mark', to indicate that both locator619# and WebElement args are valid620def _predicate(driver: WebDriverOrWebElement):621target = mark622if not isinstance(target, WebElement): # if given locator instead of WebElement623target = driver.find_element(*target) # grab element at locator624element = visibility_of(target)(driver)625if element and element.is_enabled():626return element627return False628629return _predicate630631632def staleness_of(element: WebElement) -> Callable[[Any], bool]:633"""Wait until an element is no longer attached to the DOM.634635Parameters:636-----------637element : WebElement638The element to wait for.639640Returns:641-------642boolean : False if the element is still attached to the DOM, true otherwise.643644Example:645--------646>>> from selenium.webdriver.common.by import By647>>> from selenium.webdriver.support.ui import WebDriverWait648>>> from selenium.webdriver.support import expected_conditions as EC649>>> is_element_stale = WebDriverWait(driver, 10).until(EC.staleness_of(driver.find_element(By.CLASS_NAME, "foo")))650"""651652def _predicate(_):653try:654# Calling any method forces a staleness check655element.is_enabled()656return False657except StaleElementReferenceException:658return True659660return _predicate661662663def element_to_be_selected(element: WebElement) -> Callable[[Any], bool]:664"""An expectation for checking the selection is selected.665666Parameters:667-----------668element : WebElement669The WebElement to check.670671Returns:672-------673boolean : True if the element is selected, False otherwise.674675Example:676--------677>>> from selenium.webdriver.common.by import By678>>> from selenium.webdriver.support.ui import WebDriverWait679>>> from selenium.webdriver.support import expected_conditions as EC680>>> is_selected = WebDriverWait(driver, 10).until(EC.element_to_be_selected(driver.find_element(681By.CLASS_NAME, "foo"))682)683"""684685def _predicate(_):686return element.is_selected()687688return _predicate689690691def element_located_to_be_selected(locator: tuple[str, str]) -> Callable[[WebDriverOrWebElement], bool]:692"""An expectation for the element to be located is selected.693694Parameters:695-----------696locator : Tuple[str, str]697Used to find the element.698699Returns:700-------701boolean : True if the element is selected, False otherwise.702703Example:704--------705>>> from selenium.webdriver.common.by import By706>>> from selenium.webdriver.support.ui import WebDriverWait707>>> from selenium.webdriver.support import expected_conditions as EC708>>> is_selected = WebDriverWait(driver, 10).until(EC.element_located_to_be_selected((By.CLASS_NAME, "foo")))709"""710711def _predicate(driver: WebDriverOrWebElement):712return driver.find_element(*locator).is_selected()713714return _predicate715716717def element_selection_state_to_be(element: WebElement, is_selected: bool) -> Callable[[Any], bool]:718"""An expectation for checking if the given element is selected.719720Parameters:721-----------722element : WebElement723The WebElement to check.724is_selected : bool725726Returns:727-------728boolean : True if the element's selection state is the same as is_selected729730Example:731--------732>>> from selenium.webdriver.common.by import By733>>> from selenium.webdriver.support.ui import WebDriverWait734>>> from selenium.webdriver.support import expected_conditions as EC735>>> is_selected = WebDriverWait(driver, 10).until(736... EC.element_selection_state_to_be(driver.find_element(By.CLASS_NAME, "foo"), True)737... )738"""739740def _predicate(_):741return element.is_selected() == is_selected742743return _predicate744745746def element_located_selection_state_to_be(747locator: tuple[str, str], is_selected: bool748) -> Callable[[WebDriverOrWebElement], bool]:749"""An expectation to locate an element and check if the selection state750specified is in that state.751752Parameters:753-----------754locator : Tuple[str, str]755Used to find the element.756is_selected : bool757758Returns:759-------760boolean : True if the element's selection state is the same as is_selected761762Example:763--------764>>> from selenium.webdriver.common.by import By765>>> from selenium.webdriver.support.ui import WebDriverWait766>>> from selenium.webdriver.support import expected_conditions as EC767>>> is_selected = WebDriverWait(driver, 10).until(EC.element_located_selection_state_to_be(768(By.CLASS_NAME, "foo"), True)769)770"""771772def _predicate(driver: WebDriverOrWebElement):773try:774element = driver.find_element(*locator)775return element.is_selected() == is_selected776except StaleElementReferenceException:777return False778779return _predicate780781782def number_of_windows_to_be(num_windows: int) -> Callable[[WebDriver], bool]:783"""An expectation for the number of windows to be a certain value.784785Parameters:786-----------787num_windows : int788The expected number of windows.789790Returns:791-------792boolean : True when the number of windows matches, False otherwise.793794Example:795--------796>>> from selenium.webdriver.support.ui import WebDriverWait797>>> from selenium.webdriver.support import expected_conditions as EC798>>> is_number_of_windows = WebDriverWait(driver, 10).until(EC.number_of_windows_to_be(2))799"""800801def _predicate(driver: WebDriver):802return len(driver.window_handles) == num_windows803804return _predicate805806807def new_window_is_opened(current_handles: list[str]) -> Callable[[WebDriver], bool]:808"""An expectation that a new window will be opened and have the number of809windows handles increase.810811Parameters:812-----------813current_handles : List[str]814The current window handles.815816Returns:817-------818boolean : True when a new window is opened, False otherwise.819820Example:821--------822>>> from selenium.webdriver.support.ui import By823>>> from selenium.webdriver.support.ui import WebDriverWait824>>> from selenium.webdriver.support import expected_conditions as EC825>>> is_new_window_opened = WebDriverWait(driver, 10).until(EC.new_window_is_opened(driver.window_handles))826"""827828def _predicate(driver: WebDriver):829return len(driver.window_handles) > len(current_handles)830831return _predicate832833834def alert_is_present() -> Callable[[WebDriver], Union[Alert, Literal[False]]]:835"""An expectation for checking if an alert is currently present and836switching to it.837838Returns:839-------840Alert : The Alert once it is located.841842Example:843--------844>>> from selenium.webdriver.support.ui import WebDriverWait845>>> from selenium.webdriver.support import expected_conditions as EC846>>> alert = WebDriverWait(driver, 10).until(EC.alert_is_present())847848Notes:849------850If the alert is present it switches the given driver to it.851"""852853def _predicate(driver: WebDriver):854try:855return driver.switch_to.alert856except NoAlertPresentException:857return False858859return _predicate860861862def element_attribute_to_include(locator: tuple[str, str], attribute_: str) -> Callable[[WebDriverOrWebElement], bool]:863"""An expectation for checking if the given attribute is included in the864specified element.865866Parameters:867-----------868locator : Tuple[str, str]869Used to find the element.870attribute_ : str871The attribute to check.872873Returns:874-------875boolean : True when the attribute is included, False otherwise.876877Example:878--------879>>> from selenium.webdriver.common.by import By880>>> from selenium.webdriver.support.ui import WebDriverWait881>>> from selenium.webdriver.support import expected_conditions as EC882>>> is_attribute_in_element = WebDriverWait(driver, 10).until(883... EC.element_attribute_to_include((By.CLASS_NAME, "foo"), "bar")884... )885"""886887def _predicate(driver: WebDriverOrWebElement):888try:889element_attribute = driver.find_element(*locator).get_attribute(attribute_)890return element_attribute is not None891except StaleElementReferenceException:892return False893894return _predicate895896897def any_of(*expected_conditions: Callable[[D], T]) -> Callable[[D], Union[Literal[False], T]]:898"""An expectation that any of multiple expected conditions is true.899900Parameters:901-----------902expected_conditions : Callable[[D], T]903The list of expected conditions to check.904905Returns:906-------907T : The result of the first matching condition, or False if none do.908909Example:910--------911>>> from selenium.webdriver.common.by import By912>>> from selenium.webdriver.support.ui import WebDriverWait913>>> from selenium.webdriver.support import expected_conditions as EC914>>> element = WebDriverWait(driver, 10).until(915... EC.any_of(EC.presence_of_element_located((By.NAME, "q"),916... EC.visibility_of_element_located((By.NAME, "q"))))917918Notes:919------920Equivalent to a logical 'OR'. Returns results of the first matching921condition, or False if none do.922"""923924def any_of_condition(driver: D):925for expected_condition in expected_conditions:926try:927result = expected_condition(driver)928if result:929return result930except WebDriverException:931pass932return False933934return any_of_condition935936937def all_of(938*expected_conditions: Callable[[D], Union[T, Literal[False]]],939) -> Callable[[D], Union[list[T], Literal[False]]]:940"""An expectation that all of multiple expected conditions is true.941942Parameters:943-----------944expected_conditions : Callable[[D], Union[T, Literal[False]]]945The list of expected conditions to check.946947Returns:948-------949List[T] : The results of all the matching conditions, or False if any do not.950951Example:952--------953>>> from selenium.webdriver.common.by import By954>>> from selenium.webdriver.support.ui import WebDriverWait955>>> from selenium.webdriver.support import expected_conditions as EC956>>> elements = WebDriverWait(driver, 10).until(957... EC.all_of(EC.presence_of_element_located((By.NAME, "q"),958... EC.visibility_of_element_located((By.NAME, "q"))))959960Notes:961------962Equivalent to a logical 'AND'.963Returns: When any ExpectedCondition is not met: False.964When all ExpectedConditions are met: A List with each ExpectedCondition's return value.965"""966967def all_of_condition(driver: D):968results: list[T] = []969for expected_condition in expected_conditions:970try:971result = expected_condition(driver)972if not result:973return False974results.append(result)975except WebDriverException:976return False977return results978979return all_of_condition980981982def none_of(*expected_conditions: Callable[[D], Any]) -> Callable[[D], bool]:983"""An expectation that none of 1 or multiple expected conditions is true.984985Parameters:986-----------987expected_conditions : Callable[[D], Any]988The list of expected conditions to check.989990Returns:991-------992boolean : True if none of the conditions are true, False otherwise.993994Example:995--------996>>> from selenium.webdriver.common.by import By997>>> from selenium.webdriver.support.ui import WebDriverWait998>>> from selenium.webdriver.support import expected_conditions as EC999>>> element = WebDriverWait(driver, 10).until(1000... EC.none_of(EC.presence_of_element_located((By.NAME, "q"),1001... EC.visibility_of_element_located((By.NAME, "q"))))10021003Notes:1004------1005Equivalent to a logical 'NOT-OR'. Returns a Boolean1006"""10071008def none_of_condition(driver: D):1009for expected_condition in expected_conditions:1010try:1011result = expected_condition(driver)1012if result:1013return False1014except WebDriverException:1015pass1016return True10171018return none_of_condition101910201021