java - 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 与它不兼容?
请帮忙。提前致谢。
解决方案
根据您已<button>
与文本共享的 HTML,因为Save是一个Angular 元素,因此您必须诱导WebDriverWait以使该元素可单击,如下所示:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='blueFilledButton ng-binding'][@ng-click=\"validateIdea(validateIdeaForm)\"]"))).click();
推荐阅读
- postgresql - pglogical:列出复制集?
- python - 基于日期的带有周数的列表列表
- python - Tensorflow - 急切和图形模式之间的性能问题
- elasticsearch - 如何在 Elasticsearch 中获取重复的字段值及其计数
- laravel - 如何使用 vuejs 显示 paypal 按钮?
- php - 仅 ERR (P)SUBSCRIBE / (P)UNSUBSCRIBE Laravel Echo
- android - 从 DatePickerDialog 显示日期更容易
- spring-security - 如何在 Spring Security 4 中创建子级别角色?
- asp.net-web-api - 使用 WebAPI 出现在 Swagger UI 中的多个端点版本
- vue.js - 如何在vue js中自动关闭菜单子侧边栏