本文介绍了元素当前不可见,因此单击按钮时可能无法与之交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的保护人代码是

element(by.dataHook("delete-button")).click();

获取:

HTML来源:

<button class="md-icon-but" type="button" ng-transclude="" ng-click="g" translate="loc" aria-label="Delete" title="Delete">
    <md-icon md-svg-icon="ass" data-hook="delete-button" class="ng-scope" aria-hidden="true"><svg xmlns="ht" width="100%" height="100%" viewBox="0 0 24 24" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"></path></svg></md-icon>
    <div class="md"></div></b>

如何解决并成功点击?

推荐答案

通常,您只需要:

browser.driver.manage().window().maximize();

请注意,当前在Chrome + Mac上,必须以不同的方式进行操作.

Note that on Chrome+Mac, currently you have to do it differently.

这是一组对他人也有帮助的东西:

Here is the set of other things that also helped others:

  • 确认没有其他与定位器匹配的元素.如果还有另一个与定位器匹配的元素实际上是不可见的,则会出现此错误.
  • 等待元素可点击:

  • verify that there are no other elements matching the locator. You can get this error if there is an another element matching the locator that is actually invisible.
  • wait for the element to be clickable:

var EC = protractor.ExpectedConditions,
    elm = $("button[title=Delete]");

browser.wait(EC.elementToBeClickable(elm), 5000);

  • 滚动到视图元素:

    var elm = $("button[title=Delete]");
    browser.executeScript("arguments[0].scrollIntoView();", elm);
    

  • 点击通过javascript :

    var elm = $("button[title=Delete]");
    browser.executeScript("arguments[0].click();", elm);
    

  • 移动到元素,然后通过浏览器操作"单击:

  • move to element and click via "browser actions":

    var elm = $("button[title=Delete]");
    browser.actions()
        .mouseMove(elm)
        .click()
        .perform();
    

  • 这篇关于元素当前不可见,因此单击按钮时可能无法与之交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    09-03 02:57