我正在使用 webpagetest.org 进行性能测试。要到达我需要测试的页面,我需要输入一些文本并单击下一步按钮,因为我无法直接到达该页面。
这是示例应用程序的链接
https://angular-z3shbr.stackblitz.io/
我正在尝试通过使用在输入中输入一些文本
document.querySelector('input').value= 'Test'
我面临的问题是,即使在文本框中输入了值后,下一个按钮仍未启用
网页脚本为
execAndWait document.querySelector('input').value = "test";
clickAndWait selector="next_button"
我尝试为输入设置 setValue,但结果相同
最佳答案
Angulars ngModel 需要触发“输入”事件才能更新模型。
如果您使用 element.value 更改输入字段的值,这与 webpagetest.org 使用的相同,则不会进行更改检测。
要解决此问题,只需在 webpagetest.org 脚本中手动执行此事件
示例脚本:
navigate https://angular-z3shbr.stackblitz.io/
setValue type=text some text
execAndWait document.getElementsByTagName('input')[0].dispatchEvent(new Event("input"));
clickAndWait innerText=Next
查看示例结果: https://www.webpagetest.org/result/180406_R3_31adbf8f109c1c54658a4f7a94157192/
关于javascript - 使用 Angular 应用程序的网页测试脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49398766/