gpt4 book ai didi

javascript - Selenium 中通过 jQuery 生成获取元素

转载 作者:太空宇宙 更新时间:2023-11-04 13:08:29 24 4
gpt4 key购买 nike

我有一个文本框。它只接受数字类型。当输入字符串和 sendKeys(Keys.TAB) 时,会弹出错误消息。此弹出窗口由 jQuery 使用 id="message_eff" 附加,并且之前不存在。

我尝试使用以下代码:

driver.findElement(By.xpath(".//*[@id='messagefor_eff']")); 

并运行我的测试。我运行了 10 次测试,但有时会出错:

org.openqa.selenium.NoSuchElementException: Unable to locate element {"method":"xpath","selector":".//*[@id='messagefor_eff']"}

如何修复此错误并使此错误再次出现?

最佳答案

尝试合并explicit wait在定位动态生成的元素之前:

WebDriverWait wait = new WebDriverWait(driver, 2);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//*[@id='messagefor_eff']")));
driver.findElement(By.xpath(".//*[@id='messagefor_eff']"));

关于javascript - Selenium 中通过 jQuery 生成获取元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34195448/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com