我正在自动化其中一个场景,其中包含输入一些详细信息,然后单击“保存”按钮。当我手动执行这些步骤时,几乎不需要 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/