【问题标题】:Protractor: element not interactable量角器:元素不可交互
【发布时间】:2020-05-07 05:26:00
【问题描述】:

我的测试因错误而失败:

元素不可交互失败:元素不可交互 (会话信息:chrome=79.0.3945.130) (驱动信息:chromedriver=79.0.3945.16 (93fcc21110c10dbbd49bbff8f472335360e31d05-refs/branch-heads/3945@{#262}),platform=Windows NT 10.0.18362 x86_64)

一些信息
硒独立 3.141.59
geckodriver v0-26.0
Google Chrome 版本 79.0.3945.130(官方版本)(64 位)
这部分代码适用于非角度页面。

正如您在下面的代码中看到的,我添加了 browser.sleep(),但没有解决我的问题 导致问题的元素在最后一行 (id('column_header_44)

  it('should compare the space size stored, against the value stored in app', function () {
        browser.driver.manage().window().maximize();
        browser.sleep(2000);
        browser.switchTo().frame(element(by.className('designer-client-frame')).getWebElement());
        browser.sleep(2000);
        element(by.css('div:nth-child(1) > .ms-Link > .ms-navbar-node-caption > span')).click();//click in Item
        browser.sleep(2000);
        element(by.css('.horizontal-flex-container-item-layout--paigVxanvxFrIsRy2U02r:nth-child(3) .thm-head-a2-font-size-1--medflat > span')).click();//click in process
        browser.sleep(2000);
        element(by.css('.ms-ContextualMenu-item:nth-child(1) .thm-popp-a2-font-stack-2--minflat')).click();//click in Time phased
        browser.sleep(3000);
       element(by.id('column_header_44')).click();//click on item no
        browser.sleep(3000);

    })

【问题讨论】:

    标签: protractor


    【解决方案1】:

    您应该避免使用browser.sleep 作为显式等待方法。请改用 Protractor 特定的方法。
    在单击之前使用等待的一个好方法是等到元素出现在 html DOM (presenceOf) 中,然后等待它可单击 (elementToBeClickable),最后执行单击操作:

    it('should compare the space size stored, against the value stored in app', async () => {
        const EC = protractor.ExpectedConditions;
        const your_element = element(by.id('column_header_44'));
    
        await browser.wait(EC.presenceOf(your_element));
        await browser.wait(EC.elementToBeClickable(your_element));
        await your_element.click();
    });
    

    【讨论】:

    • 嗨,@JoaquinCasco 谢谢你的建议。我完全按照您对我的建议更改了代码。但现在我收到一个错误:超时 - 在 jasmine.DEFAULT_TIMEOUT_INTERVAL 指定的超时内未调用异步回调。顺便说一句,我同时处理 2 个页面,第一个是 Angular,第二个(我遇到这个问题)是非 Angular。
    • 我用过这样的东西:jasmine.DEFAULT_TIMEOUT_INTERVAL = 100000000;这是在测试开始时写的
    【解决方案2】:

    它给出了这样的错误,因为它没有看到屏幕上的按钮。必须用javascript点击它。

    <input id="myHeader"/>
    
    ChromeDriver driver = null;
        var options = new ChromeOptions();
        driver = new ChromeDriver(options);
        IWebElement element = driver.FindElementById("myHeader");
        IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;
        executor.ExecuteScript("arguments[0].click();", element);
    

    【讨论】:

      猜你喜欢
      • 2019-05-12
      • 1970-01-01
      • 2019-10-05
      • 1970-01-01
      • 2019-11-25
      • 2020-02-08
      • 2021-10-20
      • 2021-07-08
      • 2021-08-02
      相关资源
      最近更新 更多