首页 > 解决方案 > Selenium 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 与它不兼容?

请帮忙。提前致谢。

标签: javaseleniumselenium-webdriverwebdriver

解决方案


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

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

推荐阅读