2

How could I wait until one of two elements is visible? I'm currently using ExpectedConditions - example of usage is,

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));

IWebElement waitresponse = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("example')]")));

but that is only relevant to one element, how can I add a OR?

Attempted example,

IWebElement waitresponse = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("example')]") || (By.XPath("Example2")));

However no luck using

||

maybe my syntax is wrong?

R2-D2
  • 143
  • 1
  • 9
  • This might be a way of accomplishing it: https://stackoverflow.com/questions/5350666/xpath-or-operator-for-different-nodes – Monofuse Jun 07 '19 at 21:39

2 Answers2

2

Update the line as below

IWebElement waitresponse = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("xpath1|xpath2")));
supputuri
  • 13,644
  • 2
  • 21
  • 39
-1
driver= webdriver.Firefox()

def wait():
enter code here
if len(driver.find_elements_by_tag_name('whatever')) == 1:

   do whatever you have to do
else:
time.sleep(5)
wait()
marie1995
  • 59
  • 1
  • 3
  • 8
  • The OP want to check for if either of the elements visible. I don't prefer `len(driver.find_elements_by_tag_name('whatever'))` as there may be other elements with same tag already present on the page, which will give the false positive. – supputuri Jun 07 '19 at 21:38
  • its not what OP asked – ladorm Apr 12 '20 at 14:59