Skip to content

Is it possible to wait for one of multiple elements with SeleniumBase? #2788

Closed Answered by subh-sk
krishpuri asked this question in Q&A
Discussion options

You must be logged in to vote

hii @krishpuri ,

Below is a solution that leverages the WebDriverWait and EC.any_of methods from Selenium to wait for any one of multiple elements to be present. This approach can be integrated seamlessly into a SeleniumBase test case.

from seleniumbase import SB, BaseCase
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

def wait_for_any_element(sb: BaseCase):
    sb.driver.get("https://www.google.com")
    
    WebDriverWait(sb.driver, 10).until(EC.any_of(
                EC.presence_of_element_located((By.XPATH, 'elem1')),
                EC.presence_of_element_located((By.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by mdmintz
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants