使用pressKey来模拟typeText不会产生所需的结果

问题描述 投票:1回答:2

因为作为我正在测试的站点上的输入字段是由站点开发人员使用随机类创建的,所以typeText将无法工作,因为Testcafe不会将其识别为有效的输入字段。

因此,我正在尝试使用pressKey来模拟typeText以在输入字段中输入字符串。

不幸的是,结果并不是我所希望的。使用.pressKey('L P')应该导致LP出现在搜索框中,而是出现LPL

我该如何解决这个问题?我不知道为什么有另一个L出现在它不应该的地方。

作为参考,使用typeText会导致显示为错误:

Uncaught TypeError: this.ui.searchBox.val is not a function

为了进一步参考,选择器如下所示:

#modals > div.selectra-dropdown > div > div.search > input[type="zax"]

在查询“zax”到底是什么时,网站开发人员告诉我,这是一个编组的类名,用作某个问题的解决方法,我坚持使用它。

automated-tests e2e-testing web-testing testcafe
2个回答
3
投票

可能这意味着TestCafe无法正确模拟页面的键盘事件。请创建一个bug report并提供可用于重现该问题的页面和测试。


2
投票

TBH,我真的希望你找到答案,但由于那个type=[zax],对我来说,这里无法提供帮助;但是,你可以简化代码并尝试类似的东西

  1. this.empty_lp_group_search = Selector('#modals > div.selectra-dropdown > div > div.search > input[type="zax"]');替换这里this.empty_lp_group_search = Selector('#modals input[type="zax"]');
  2. 也许这个this.empty_lp_group_select = Selector('#link-resources > div.modal-host > div.modal-element.modal-container > div > div.modal-body > div.form-container > div > div.lp-chooser-container > div > div > div > div > div');与这个this.empty_lp_group_select = Selector('#link-resources div.nth(12)');;这最后一个是基于这个链接在这里https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/selectors/functional-style-selectors.html#nth
© www.soinside.com 2019 - 2024. All rights reserved.