【问题标题】:Not able to click on the Add button无法点击添加按钮
【发布时间】:2021-03-18 23:28:46
【问题描述】:
<div class="MuiGrid-root jss48321 MuiGrid-item MuiGrid-grid-xs-12 MuiGrid-grid-sm-3 MuiGrid-grid-md-3 MuiGrid-grid-lg-3 MuiGrid-grid-xl-3">
<h4 class="MuiTypography-root jss48324 MuiTypography-h4">Decks</h4>
<button class="MuiButtonBase-root MuiFab-root jss48323 MuiFab-sizeSmall MuiFab-primary" tabindex="0" type="button" aria-label="add" title="Add">
<span class="MuiFab-label">
<svg class="MuiSvgIcon-root" focusable="false" viewBox="0 0 24 24" aria-hidden="true">
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"></path>
</svg>
</span>
<span class="MuiTouchRipple-root"></span>
</button></div>

由于是react js应用,所以我加了

browser.waitForAngularEnabled(false); 

这里我想点击添加图标 (+)

我的测试脚本:

describe('IEC', function () {
it('Login', function () {
browser.waitForAngularEnabled(false);
browser.get('cannot provide the url since it requires VPN');
element(by.css('input[type="text"]')).sendKeys('12345');
element(by.css('input[type="password"]')).sendKeys('Pwd');
element(by.buttonText('Login')).click();
element(by.css('button[title="Add"]')).click();
});
});

输出:

失败:使用定位器找不到元素:By(css selector, button[title="Add"])

我该如何解决这个问题?#

【问题讨论】:

  • 你添加了显式等待
  • 我同意上述评论,您需要创建自己的显式等待。所以像浏览器一样。等待DOM中的元素(我认为是isPresent)
  • 你需要提供完整的代码 sn-p 而不仅仅是你认为它不起作用的那一行
  • 嗨@SergeyPleshakov 现在添加了完整的代码。请检查。
  • 嗨@PDHide,我尝试了显式等待,它奏效了。非常感谢

标签: reactjs jasmine protractor


【解决方案1】:

Protractor 内置了特定于 Angular 页面的等待。您的页面已做出反应,通过运行 browser.waitForAngularEnabled(false); 您可以禁用该等待

现在您的代码将按照您的指示执行操作:设置用户名和密码,然后单击提交。可能 5 毫秒后您尝试单击添加按钮?但它不存在。我很确定登录后加载应用程序至少需要 10 秒。所以您需要添加该步骤。 browser.sleep(15000) 是非常糟糕的做法,使用 browser.wait 添加显式等待条件

此外,您的代码的每一行都返回 Promise,但您不处理它。副作用是无法保证您的命令顺序。我已经在之前的帖子中告诉过你,你需要使用async/await。除非你这样做,否则你会遇到成千上万的问题,我保证

【讨论】:

  • 嗨@Sergey Pleshakov,现在有了更好的理解。我可能会想念你在上一篇文章中的 cmets。任何方式感谢您的澄清。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-07-14
  • 2011-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-24
相关资源
最近更新 更多