java - 无法使用 Selenium Java webdriver 单击锚点 href 元素
问题描述
下面是html代码:
<a href="javascript:void(0)">
STK10000251
VESUVIUS29
Vesuvius India Ltd
</a>
我写了以下xpath:
driver.findElement(By.xpath("//a[contains(text(), 'STK10000251')]")).click();
执行上述语句后,我收到以下错误:
线程“主”org.openqa.selenium.StaleElementReferenceException 中的异常:过时的元素引用:元素未附加到页面文档
我在哪里弄错了
解决方案
诱导WebDriverWait
() 并等待elementToBeClickable
()
WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(text(), 'STK10000251')]")));
element.click();
推荐阅读
- opencl - 如何使用 aocl 诊断命令确定 FPGA 板的设备名称和 aocx_file?
- javascript - 将 jquery .getJSON 转换为 ajax 异步等待 YouTube API
- xml - 用于从 CSV 文件修改 XML 的 Powershell 脚本
- react-native - 点击 wonderPush 通知不要打开我的应用程序
- c++ - 将 CLIPS 嵌入 C++ 应用程序 - 从 C++ 与 CLIPS 交互
- java - Cucumber Selenium 的自动化逻辑
- javascript - 使用 jquery 重新加载页面后运行另一个脚本
- python - 我尝试使用函数旋转矩形,但框位置不正确
- entity-framework - 在 Blazor .Net Framework 中使用 ADO.NET 实体模型 (.edmx)
- ios - UIButton 数组未保存在本地。怎么了?