javascript - 无法点击元素

标签 javascript protractor

<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); 
在这里我想点击添加图标(+)
我的测试脚本。
element(by.css('svg[class="MuiSvgIcon-root"]')).click();
输出:失败:使用定位器找不到元素:By(css selector, svg[class="MuiSvgIcon-root"])任何人都可以帮助我解决这个问题。

最佳答案

尝试这个

it('test case', async () => {
  let plusIcon = element(by.css('svg[class="MuiSvgIcon-root"]'))
  await browser.waitForAngularEnabled(false); 
  // your steps prior to click
  await browser.wait(
    ExpectedConditions.presenseOf(plusIcon),
    15000
  );
  await plusIcon.click();
});

关于javascript - 无法点击元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66149644/

相关文章:

javascript - 错误: cannot find module electron while testing by mocha and spectron in electron-compile app

javascript - 使图像可拖动到 HTML5 Canvas,将图像移出 Canvas

angularjs - 失败 : Timed out waiting for Protractor to synchronize with the page

angularjs - Protractor :don't wait for elements to appears in Dom

javascript - Angular JS 如何使用 Protractor 获取中继器的所有行?

node.js - 如何从 Node 命令开始运行 Protractor ?

javascript - 单击动态生成的按钮

javascript - Angular - 单元测试主题()?

c# - 将日期参数传递给对 MVC 操作的 ajax 调用的安全方法

javascript - 异步迭代对象键/值