单击按钮后等待类加载值

2024-10-01 11:30:19 发布

您现在位置:Python中文网/ 问答频道 /正文

加载网站后,我成功单击一个按钮,该按钮将在此类中生成一些数字

<div class="styles__Value-sc-1bfbyy7-2 eVmhyz"></div>

但不是马上,它会把它们一个接一个地放进去。Selenium将立即获取放入类中的第一个值,但不会等待添加其他值。任何方法都可以等待它在抓取之前加载其中的所有值

以下是我用于获取值的python代码:

total = driver.find_element_by_xpath("//div[@class='styles__Value-sc-1bfbyy7-2 eVmhyz']").text

Tags: 方法代码divvalue网站driverselenium数字
1条回答
网友
1楼 · 发布于 2024-10-01 11:30:19

硒有一种WebDriverWait方法:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions

browser = webdriver.Chrome()
delay = 5
total = WebDriverWait(browser, delay).until(expected_conditions.presence_of_element_located(<locator>)

我还没有在本地测试过它,但它可能会工作。还有presence_of_all_elements_located方法,您可以在this页面上找到详细信息

希望这有帮助

相关问题 更多 >