我想获取一个DOM元素,该元素在页面加载时不存在,但之后使用脚本添加。确切的情况如下:
我加载了https://www.binance.com/de/trade/pro/XRP_BTC
我点击" TradingView"按钮
我在" Technical Ind"按钮上选择" Stochastic RSI"。
(所有这些步骤都由驱动程序本身使用click()或机器人通过按键和鼠标操作来处理)
选择了随机RSI后,无需添加页面刷新即可添加新的DOM元素。我正在寻找具有类名"pane-legend-item-value-wrap"的元素,这些元素是在添加"随机RSI"后生成的。
调用driver.findElements(By.className("pane-legend-item-value-wrap"))给我0个结果。我认为那是由于驱动程序页面源仍然是第一次立即加载页面后的源。有没有一种方法可以刷新页面源代码或DOM树,而无需重新加载整个页面?
我尝试了隐式和显式等待,但仍未成功,并出现以下错误:
Exception in thread"main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for presence of any elements located by By.className: pane-legend-item-value-wrap (tried for 15 second(s) with 500 milliseconds interval)
这是相关代码:
public class Main {
public static void main(String args[]) {
try {
Selenium selenium = new Selenium();
selenium.startChrome();
for (int i = 0; i < 30000; i++) {
try {
selenium.getChromeDriver().getTitle();
} catch (WebDriver