java - Selenium WebDriver - 单击“保存”按钮后应用程序变得无响应

标签 java selenium selenium-webdriver webdriver

我正在自动化其中一个场景,其中包含输入一些详细信息,然后单击“保存”按钮。当我手动执行这些步骤时,几乎不需要 5 到 8 秒来处理和完成。 但是通过自动化脚本执行相同的操作,它只是继续加载无限时间。

下面是保存按钮的 html 代码:

<button class="blueFilledButton ng-binding" ng-click="validateIdea(validateIdeaForm)" ng-disabled="userNotFound || PoupupButtonDisabled || incorrectValidDate" tabindex="0" aria-disabled="false">Save</button>

Selenium 代码:​​我尝试过以下点击方法:

案例 - 1:

driver.findElement(By.xpath("//button[text()='Save']")).click();

案例 - 2:

Actions builder = new Actions(driver);
builder.moveToElement(driver.findElement(By.xpath("//button[text()='Save']"))).click().perform();

在这两种情况下,它都会继续加载。

是否是因为点击“保存”按钮后调用了任何脚本,而 webdriver 与其不兼容?

请帮忙。提前致谢。

最佳答案

根据 HTML,您已共享 <button>文本为 Save 是一个 Angular 元素,因此您必须诱导 WebDriverWait 以使元素可点击,如下所示:

new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='blueFilledButton ng-binding'][@ng-click=\"validateIdea(validateIdeaForm)\"]"))).click();

关于java - Selenium WebDriver - 单击“保存”按钮后应用程序变得无响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50175153/

相关文章:

windows - "Bundle"带浏览器的 selenium 应用程序?

java - 如何让代码模块化?

java - 如何从JSP页面另存为pdf?

python - 使用带有自定义 firefox 配置文件的 Selenium webdriver - 如何摆脱插件弹出窗口

python - Selenium 属性错误 : list object has no attribute find_element_by_xpath

python - 在 Selenium 中显示当前光标位置

Java - 并发修改异常

java - 在 Java 中将 replaceAll 与包含特殊字符的字符串一起使用

Selenium Chromedriver 导致 Chrome 在没有配置插件、书签和其他设置的情况下启动

java - 在 cucumber 中自动打开多个浏览器窗口