javascript - JavaScript xPath 命令不会在每次运行时与 Selenium Java 程序混合运行
问题描述
下面的 javascript(与 Selenium 中的 Java 混合)不会在每次运行时成功运行 xpath 命令。但是我的 Java 命令运行成功,这是我遇到问题的 xpath。(换句话说,有时 xpath 命令会成功运行,而有时则不会)。我将 jdk 从 13 更改为 jdk8,但这没有用。我不知道需要什么。
我是学习自动化测试的新手,我正在自学。
这是命令行:
driver.findElement(By.xpath("//button[@type='button' and @data-test-id='checkbox']")).click();
错误响应:
JavaScript error: , line 0: NotAllowedError: The play method is not
allowed by the user agent or the platform in the current context,
possibly because the user denied permission.
Exception in thread "main"
org.openqa.selenium.StaleElementReferenceException: The element
reference of <button class="c27KHO0_n b_0 M_0 i_0 I_T y_Z2uhb3X
A_6EqO r_P C_q cvhIH6_T ir3_1JO2M7 P_0" type="button"> is stale;
either the element is no longer attached to the DOM, it is not
in the current frame context, or the document has been refreshed
解决方案
StaleElementReferenceException:当元素未附加到 DOM 时发生,请使用显式等待和检查:
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(
ExpectedConditions.elementToBeClickable(By.xpath("//button[@type='button' and @data-test-id='checkbox']"))).click();
推荐阅读
- java - Ant 期间使用不同的 java 版本
- python - 如何让 Flask 应用程序使用 css 和图像?
- javascript - 如何在chart.js中设置折线图中的行数?
- javascript - Promise 中的 Angularfire v6 未定义 AngularFireStore
- javascript - 如何将 Promise 与嵌套的 foreach 一起使用
- python - 如何使用 Seaborn 手动添加图例
- ios - 实例方法 'application(application:handleOpenURL:)' 几乎符合可选要求
- github - 如何在 GitHub 上部署 mdbook
- mongodb - MongoDB:使用 ObjectID 并可能在多个集合上进行通配符搜索
- sql - 验证记录以更新字段 PL/SQL