【问题标题】:Asserting the background image of a page with selenium用 selenium 断言页面的背景图像
【发布时间】:2009-11-26 21:39:23
【问题描述】:

我有一个应用程序,用户可以在其中更改其个人资料页面的背景图像。因此,我并不是断言,当用户更改图像时,图像实际上会发生变化。我一辈子都想不出一个 CSS 选择器或 xpath 来完成这项工作。这是我拥有的 HTML:

<body style="background:#FFFFFF url(/uploads/images/000/000/002/original.png?1257966819) no-repeat 0 0;" class="users users-show-edit layout-main-with-sidebar" id="users-edit">

有什么建议吗?

【问题讨论】:

    标签: xpath selenium css-selectors


    【解决方案1】:

    我使用了以下内容,但我认为它可能需要调整才能跨多个浏览器工作 - 我主要在 Firefox 中进行测试:

    selenium.getEval("this.findEffectiveStyleProperty(this.browserbot.findElement(\"" + locator + "\"), \"backgroundImage\")");
    

    【讨论】:

      【解决方案2】:

      我最后还是这样做了,有点小题大做,但完成了工作:

        html = browser.get_html_source
        assert html.include?("#{@background.background_image.url}")
      

      【讨论】:

        猜你喜欢
        • 2013-12-06
        • 2016-03-30
        • 1970-01-01
        • 2018-05-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-12
        相关资源
        最近更新 更多