【问题标题】:Selecting hidden elements when using protractorjs with phantomjs将 protractorjs 与 phantomjs 一起使用时选择隐藏元素
【发布时间】:2014-02-26 01:53:25
【问题描述】:

在我最近的一篇文章中,我遇到了隐藏元素的问题(请参阅Here)。从那时起,我已经从 chrome 驱动程序转移到 phantomjs 进行无头测试。

我的问题是这个。

由于选择隐藏元素的移动会导致下面的错误

UnknownError: Error Message => ''undefined' is not a function (evalating 'arguments[0].click()')'

在 chrome (webdriver) 中运行很好,所有测试都通过了,但 phantomjs 似乎不喜欢这种方法。是否有另一种解决此问题的方法,可以使用phantomjsprotractorjs 在测试中运行。

编辑 下面的测试是我遇到的问题

it('should redirect to addresses', function () {
        var hiddenWebElement = ptor.driver.findElement(by.css('ul#myaccount li:nth-child(2) a'));
        ptor.driver.executeScript("arguments[0].click()",hiddenWebElement).then(function() {
            expect(ptor.driver.getCurrentUrl()).toContain('#/addresses');
        });
    }, 15000);

我的配置文件是

// An example configuration file.
exports.config = {
    // The address of a running selenium server.
    seleniumAddress: 'http://localhost:4444/wd/hub',
    baseUrl: 'http://localhost:52254',
    // Capabilities to be passed to the webdriver instance.
    capabilities: {
        'browserName': 'phantomjs'
    },

    // Spec patterns are relative to the current working directly when
    // protractor is called.
    specs: [
        'Scenarios/account_spec.js',
        'Scenarios/add_address_spec.js'
    ],

    // Options to be passed to Jasmine-node.
    jasmineNodeOpts: {
        showColors: true,
        defaultTimeoutInterval: 30000
    }
};

需要注意的一点是,高于此运行的所有测试都期望低于该运行的测试在尝试查找元素时再次出现问题

it('should redirect to login', function () {
        ptor.driver.findElement(by.id('headerLoginBtn')).click().then(function () {
            expect(ptor.driver.getCurrentUrl()).toContain('/Account/Login');
        });
    }, 15000);

抛出异常的元素是不可见的。我在这种情况下的测试也使用了 ptor.driver,因为这些页面包含 c# ASP.NET 代码。

【问题讨论】:

  • 你能分享更多你的测试代码吗?该错误看起来像是您的测试中有问题,而不是来自 webdriver 的错误。
  • 出于兴趣,为什么要点击隐藏元素?量角器测试旨在复制用户行为,用户不能点击隐藏元素。 (不过,我并不是说工具不能用于其他目的)
  • 我有一个按钮可以激活下拉菜单,直到该按钮悬停在菜单上才会出现。因此需要选择隐藏元素。
  • Jmr,测试很好,因为它通过 webdriver 在 chrome 下运行,而不是在 phantomjs 下。
  • 我也有同样的问题。适用于 Firefox 而不是 phantomjs。你解决了吗?

标签: angularjs phantomjs protractor


【解决方案1】:

我找到了一种解决方法,这对我来说似乎是唯一可行的方法。我删除了隐藏元素的 css,然后单击它并且它起作用了。我正在使用 selenium,但它应该是您的类似解决方案

    executeJavaScript("$('.log-out').removeClass('hide');");
    driver.findElement(By.className("log-out")).click();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-03
    • 1970-01-01
    • 1970-01-01
    • 2020-11-17
    • 2017-07-09
    • 1970-01-01
    • 2023-03-22
    相关资源
    最近更新 更多