代码之家  ›  专栏  ›  技术社区  ›  Matthew Dewell

量角器/角度无法单击可单击图标

  •  0
  • Matthew Dewell  · 技术社区  · 6 年前

    我有以下的量角器/角度脚本:

    clickAppMenuIcon() {
        var EC = protractor.ExpectedConditions;
        var menuLayer = element(by.id('cdk-overlay-2'));
        expect(menuLayer.isPresent()).toBe(true)
        .then(function (){
            console.log('menu Layer shows');
            var menuGrid = element(by.css('.menu-grid'));
            expect(menuGrid.isPresent()).toBe(true)
            .then(function () {
                console.log('menu-grid shows');
                browser.executeScript('' +
                    'var zIndexElement0 = document.getElementById("app-container");' +
                    'zIndexElement0.style.zIndex = "-20";' +
                    'var zIndexElement1 = document.getElementById("cdk-overlay-2");' +
                    'zIndexElement1.style.zIndex = "20";'
    
                );
                menuGrid.click();
                var menuIcon = element(by.css('a[title=Configuration]'));
                expect(menuIcon.isPresent()).toBe(true)
                .then(function() {
                    console.log("menu Icon is present");
                    menuIcon.click();
                    var routerLinkIcon = element.all(by.css('.material-icons'));
                    expect(routerLinkIcon.isPresent()).toBe(true)
                    .then(function (){
                       console.log("it's there");
                       routerLinkIcon.click();
                       // browser.wait(function (){
                           // expect(browser.driver.getCurrentUrl()).toEqual('http://10.22.1.68:8080/configuration');
                       // },5000);
                       expect(browser.driver.getCurrentUrl()).toEqual('http://10.22.1.68:8080/configuration');
                    });
                });
            });
        });
    }
    

    这适用于Angular HTML:

    <mat-card _ngcontent-c8="" class="app-menu mat-card ng-star-inserted">
      <div _ngcontent-c8="" class="menu-grid">
        <a _ngcontent-c8="" title="NPW">
          <i _ngcontent-c8="" class="material-icons">account_balance</i>
        </a>
        <a _ngcontent-c8="" title="Upload">
          <i _ngcontent-c8="" class="material-icons">file_upload</i>
        </a>
        <a _ngcontent-c8="" title="Correlate">
          <i _ngcontent-c8="" class="material-icons">share</i>
        </a>
        <a _ngcontent-c8="" routerlink="workspaces" title="Workspace" ng-reflect-query-params="[object Object]" ng-reflect-router-link="workspaces" href="/workspaces">
          <i _ngcontent-c8="" class="material-icons">content_copy</i>
        </a>
        <a _ngcontent-c8="" title="Help">
          <i _ngcontent-c8="" class="material-icons">help</i>
        </a>
        <a _ngcontent-c8="" title="Send Notification">
          <i _ngcontent-c8="" class="material-icons">add_alert</i>
        </a>
        <a _ngcontent-c8="" routerlink="configuration" title="Configuration" ng-reflect-router-link="configuration" href="/configuration">
          <i _ngcontent-c8="" class="material-icons">settings_applications</i>
        </a>
      </div>
    </mat-card>
    

    它在控制台中返回找到它,然后它应该可以单击以将URL重定向到新的URL,但它似乎坐在那里什么也不做,除了返回此错误:

    **************************************************
    *                    Failures                    *
    **************************************************
    
    1) ConfigNavCheck should navigate to Configuration page on click
      - Failed: Element not clickable at point (450,676). Other element would receive the click: <div class="mat-button-ripple mat-ripple mat-button-ripple-round" ng-reflect-disabled="false" ng-reflect-trigger="[object HTMLButtonElement]" matRipple="" ng-reflect-centered="true"></div>
      Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:08.936Z'
      System info: host: 'A0000872', ip: '10.22.73.23', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_77'
      Driver info: driver.version: unknown
    
    Executed 1 of 1 spec (1 FAILED) in 20 secs.
    [13:58:50] I/local - Shutting down selenium standalone server.
    [13:58:50] I/launcher - 0 instance(s) of WebDriver still running
    [13:58:50] I/launcher - internet explorer #01 failed 1 test(s)
    [13:58:50] I/launcher - overall: 1 failed spec(s)
    [13:58:50] E/launcher - Process exited with error code 1
    

    如何将页面重定向到单击的链接。我们试过了,等一下,时间到了。我们还有一个更简单的版本,可以很好地与Chrome和Firefox配合使用,但不适用于IE11。IE必须得到支持,所以这是必要的。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Matthew Dewell    6 年前

    我知道这样做会引起一些不好的评论,但它至少在Chrome和火狐中有效。

    browser.executeScript('document.querySelector(\'[routerlink=“configuration”]\').click();');

    现在,如果您在单击某个元素时遇到问题,而不是像我在许多量角器登录问题中看到的那样单击其他元素,那么可以使用:

    changeZindexById(zIndexLayer, level) {
        console.log('zIndex level: ' + level);
        browser.executeScript('' +
            'var zIndexElement = document.getElementByID("' + zIndexLayer + '");' +
            'zIndexElement.style.zIndex = "' + level + '";'
        );
    }
    
    changeZindexByClass(zIndexLayer, level) {
        console.log('zIndex level: ' + level);
        browser.executeScript('' +
            'var zIndexElement = document.getElementsByClassName("' + zIndexLayer + '");' +
            'zIndexElement[0].style.zIndex = "' + level + '";'
        );
    }