-
I have a form on a webpage that can behave differently based on the input provided. So is it possible to efficiently wait for the presence of one of multiple elements? Currently, I can achieve this without SeleniumBase by using the following code:
And I know SeleniumBase has a wait_for_element_present() method, but is there a way to pass multiple selectors to it? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
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 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.XPATH, 'elem2')),
EC.presence_of_element_located((By.XPATH, 'elem3'))
))
input("wait = ")
with SB(uc=True) as sb:
wait_for_any_element(sb) This solution provides an efficient way to wait for any of the multiple elements to be present using |
Beta Was this translation helpful? Give feedback.
-
If you want to use the available SeleniumBase detection methods you can do:
|
Beta Was this translation helpful? Give feedback.
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.