【问题标题】:Verify color in selenium ide验证 selenium ide 中的颜色
【发布时间】:2020-08-21 15:34:55
【问题描述】:

我实际上是在寻找 selenium IDE 来测试网站的许多部分,所以我是新手。我一直在寻找验证网页元素的 css 样式属性(例如字体颜色、背景颜色等)。

我找到了很多使用“VerifyAttribute”命令的文档,但都是3到6年前的,实际版本没有这个命令,我似乎找不到任何等效的。

我已经尝试过“VerifyElementPresent”和这样的命令,但是尽管我添加了 css 属性(如 background-color=#333333),但测试总是通过,因为无论我在“值”框。

所以我的问题是:

1- 是否可以使用 Selenium IDE 验证 css 样式属性和值?

2- 如果是,我应该使用哪个命令,以及如何写入正确的预期值?

提前感谢您的帮助!

【问题讨论】:

    标签: selenium testing ide qa


    【解决方案1】:

    您可以使用execute <script> 来执行JavaScript 命令。您基本上想要获取元素的style 属性或使用getComputedStyle,具体取决于您的情况。

    以下示例适用于https://github.com/

    首先是execute 步骤

    Command : execute
    Target : return getComputedStyle(document.querySelector(".Header-old")).backgroundColor
    Value : backgroundColor
    

    在提取值后跟assert

    Command : assert
    Target : backgroundColor
    Value : "rgb(36, 41, 46)"
    

    【讨论】:

      【解决方案2】:

      rgba_value = element.value_of_css_property('color')

      driver.find_element(xpath-value) 找到元素的位置

      rgb_value = change_css_output_to_rgb_value(rgba_value)

      icon_color_name = get_colour_name(rgb_value)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-10-05
        • 1970-01-01
        • 2012-10-08
        • 1970-01-01
        • 2018-01-17
        • 2013-07-15
        • 1970-01-01
        • 2013-04-16
        相关资源
        最近更新 更多