【问题标题】:Not able to click on hidden element in protractor?(Please go through the image.)无法点击量角器中的隐藏元素?(请浏览图片。)
【发布时间】:2020-04-09 15:23:22
【问题描述】:

这是 HTML 代码:

<li class="subdropdown">
                    <a href="" class="submenu-toggle">Create Position</a>
                    <ul class="list-unstyled dropdown-submenu" role="menu">
                        <li style="cursor: pointer;">
                            <a ng-click="openPositionModal($event)"><i class="glyphicon glyphicon-list-alt"></i> New Position</a>
                        </li>

这是我的测试用例:

1) Move  the cursor on "Create position" toggle menu.
2) After the mouse hover, click on the "New position" menu list.

【问题讨论】:

    标签: selenium-webdriver protractor


    【解决方案1】:

    我使用下面的代码点击了一个隐藏元素。也许它可能会帮助某人。

    进口声明:

    import { browser, by, element } from 'protractor';
    

    代码:

    const hiddenElement = element(by.id('hiddenIcon'));
    browser.driver.executeScript('arguments[0].click();', hiddenElement.getWebElement());
    

    只需将 hiddenIcon 更改为您的元素的 id。

    【讨论】:

      【解决方案2】:

      browser.actions()、“按链接文本”和“按部分链接文本”定位器在这里应该有所帮助:

      var EC = protractor.ExpectedConditions;
      
      // open up the menu
      
      // choose position
      var choosePosition = element(by.linkText('Create Position'));
      browser.actions().mouseMove(choosePosition).perform();
      
      // choose new position
      var newPosition = $('a[ng-click*=openPositionModal]');
      browser.wait(EC.elementToBeClickable(newPosition), 3000);
      newPosition.click();
      

      【讨论】:

      • 它不工作,也没有出错......我不知道为什么......请帮助我
      • 我没有收到任何错误...它显示所有测试用例均已通过但未单击“新位置”...通过自动鼠标悬停工作但之后它是没有点击“新职位”。
      • @raghavendrat 好的,已更改定位器,请检查它现在是否适合您。谢谢。
      • 我尝试使用 css、xpath、linkText、partiallinkText 和 cssContainingText 定位器......它显示测试用例已通过,但它没有点击“新位置”。它也没有显示任何错误。
      • @raghavendrat 好的,在代码中添加了显式等待,它有帮助吗?谢谢。
      猜你喜欢
      • 1970-01-01
      • 2014-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-16
      • 2016-03-26
      • 1970-01-01
      相关资源
      最近更新 更多