python - Selenium Expected Conditions - possible to use 'or'? -
i'm using selenium 2 / webdriver python api, follows:
from selenium.webdriver.support import expected_conditions ec # code causes ajax query run webdriverwait(driver, 10).until( ec.presence_of_element_located( \ (by.css_selector, "div.some_result")));
i want wait either result returned (div.some_result
) or "not found" string. possible? kind of:
webdriverwait(driver, 10).until( \ ec.presence_of_element_located( \ (by.css_selector, "div.some_result")) \ or ec.presence_of_element_located( \ (by.css_selector, "div.no_result")) \ );
i realise css selector (div.no_result, div.some_result
), there way using selenium expected conditions method?
i did this:
class anyec: """ use webdriverwait combine expected_conditions in or. """ def __init__(self, *args): self.ecs = args def __call__(self, driver): fn in self.ecs: try: if fn(driver): return true except: pass
then call like...
from selenium.webdriver.support import expected_conditions ec # ... webdriverwait(driver, 10).until( anyec( ec.presence_of_element_located( (by.css_selector, "div.some_result")), ec.presence_of_element_located( (by.css_selector, "div.no_result")) ))
obviously trivial implement allec
class likewise.
nb. try:
block odd. confused because ecs return true/false while others throw exceptions false. exceptions caught webdriverwait anyec thing producing odd results because first 1 throw exception meant anyec didn't proceed next test.
Comments
Post a Comment