python - 等待多个图表加载
问题描述
我在一个仪表板中有多个图表。我想等到所有图表加载完毕。我在java中完成了这段代码。我想用python完成。请帮忙
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
Iterator<WebElement> eleIterator = driver.findElements(By.xpath("//img[@class='loading']")).iterator();
while (eleIterator.hasNext())
{
boolean displayed = false;
try
{
displayed = eleIterator.next().isDisplayed();
}
catch (NoSuchElementException | StaleElementReferenceException e)
{
displayed = false;
}
if (displayed)
{
return false;
}
}
}
return true;
}
});
我想要这个代码使用 python 或任何建议如何等到所有图表加载到 selenium python
解决方案
您可以使用 python 中的显式等待来等待所有元素可见或出现在 DOM 中。
WebDriverWait(driver,30).until(EC.visibility_of_all_elements_located((By.XPATH,"//img[@class='loading']")))
或者
WebDriverWait(driver,30)until(EC.presence_of_all_elements_located((By.XPATH,"//img[@class='loading']")))
要使用显式等待,您必须导入以下内容
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
推荐阅读
- sql - 带前缀和后缀的 SQL 定义
- html - 如何制作一个从 mqtt 获取变量的雷达
- conda - 我需要多少可用空间才能使用 conda 激活环境?
- asp.net - 如何从 Angular 读取 RFID 卡
- r - select(vore) 有时称为“vore”列,但有时也称为“vore_imp”列
- python - 从 S3 存储桶下载图像并存储在本地变量(boto3)中
- .net - 添加报告下载的进度条(包括源)
- ios - Array(String) 是否分配新空间?
- rpa - 有什么方法可以使用 UiPath 从冗长的 PDF 中提取表格?
- architecture - 为什么 Archimate Elements 有两种符号