When i do import from selenium.webdriver.support it have long name as expected_conditions, this can be shortenen in this way from selenium.webdriver.support import expected_conditions as EC, but how to shorten functions names inside called EC ?
for example i need shorten function like visibility_of_all_elements_located to VoAEL
to call
WebDriverWait(driver, 10).until(EC.VoAEL((By.XPATH, "//input[@role='combobox']")))
instead of
WebDriverWait(driver, 10).until(EC.visibility_of_all_elements_located((By.XPATH, "//input[@role='combobox']")))
as thoose functions name takes a lot of space in code.
So how to do that?
CodePudding user response:
The expected conditions are classes, so you can use alias when importing them as well
from selenium.webdriver.support.expected_conditions import visibility_of_all_elements_located as VoAEL
WebDriverWait(driver, 10).until(VoAEL((By.XPATH, "//input[@role='combobox']")))
I would suggest though to create a utility file with wait functions to reuse
util file:
wait = WebDriverWait(driver, 10)
def voael(by, locator):
return wait.until(EC.visibility_of_all_elements_located((by, locator)))
def poael(by, locator):
return wait.until(EC.presence_of_all_elements_located((by, locator)))
...
call:
voael(By.XPATH, "//input[@role='combobox']")
