硒等到两个元素之一可见

时间:2019-06-07 21:18:56

标签: c# selenium

我怎么能等到两个元素之一可见?我目前正在使用ExpectedConditions-使用示例是

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

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

但这仅与一个元素有关,如何添加OR?

尝试的例子,

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

但是没有运气

||

也许我的语法是错误的?

2 个答案:

答案 0 :(得分:1)

如下更新行

IWebElement waitresponse = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("xpath1|xpath2")));

答案 1 :(得分:0)

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()