【问题标题】:Protractor locator can't find html element in phantomjs only量角器定位器仅在 phantomjs 中找不到 html 元素
【发布时间】:2014-06-09 14:31:58
【问题描述】:

我有一些在 chrome 中运行良好的测试,但是如果我切换到 phantomjs,我会遇到以下错误:

Unable to find element with css selector '.selected-recipients a'

我的测试是这样的:

it('should navigate when clicking edit', function() {

    var editLink = element(by.css('.selected-recipients a')).element(by.css('.edit-preview'));

    editLink.click();
    expect(browser.getCurrentUrl()).toContain('#/recipients');
});

这在 chrome 上运行良好。问题是phantomjs。我发现一个帖子表明问题可能与窗口大小有关,但这并没有解决我的问题:

https://github.com/angular/protractor/issues/585

我也尝试使用 by.id 而不是 by.css,我也遇到了同样的问题。此文件中的所有其他测试工作正常,有些确实使用 by.css,因此 phantomjs 理解此定位器看起来不是问题。该元素似乎根本不在页面中。

有什么想法吗?谢谢

【问题讨论】:

    标签: angularjs phantomjs protractor


    【解决方案1】:

    当 phantomjs 以一种奇怪的方式行事时,我会转储一个屏幕截图。 可能不是您要找的东西,但这是一个想法。 :)

    page.open("http://www.stackoverflow.com", function()
    {
        page.render('script_ending.png');
    }
    

    另一个想法是尝试将 html 转储到文件中,以查看元素是否存在。

    或者尝试更改 DOM,插入一个元素,然后看看是否可以找到它。

    或者尝试仅通过类名搜索,看看它在什么时候失败......也许标签a没有子元素。

    【讨论】:

    • page 来自哪里?我认为browser.takeScreenshot 是在量角器中截屏的正确方法。您应该放置示例代码以将 html 转储到文件中。
    猜你喜欢
    • 1970-01-01
    • 2016-01-22
    • 2015-11-03
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多