【问题标题】:Selenium IDE - How to check whether element has some [style] attribute or not in testcase?Selenium IDE - 如何在测试用例中检查元素是否具有某些 [style] 属性?
【发布时间】:2020-02-04 20:42:56
【问题描述】:

所以,我的测试有以下命令目标值:

store attribute
id=loadGameButton
*visible*

正在尝试查找 id=loadGameButton... 失败:16:58:58

隐式等待在 30000 毫秒后超时

我试过这个How to check if a style has been applied in Selenium IDE 还有这个Selenium IDE cannot find ID

store attribute
css=#loadGameButton@style
*inline*
store attribute
css=[id='loadGameButton']
*inline*

但也不起作用:它总是返回 OK,而与我要检查的内容没有对应关系。

https://github.com/Areso/1255-burgomaster/tree/master/selenium-ide

【问题讨论】:

    标签: selenium firefox selenium-ide


    【解决方案1】:

    store attribute 不检查属性值,它只是保存选定元素的值。要检查它,您应该使用assertverify 命令。

    store attribute | css=<path_to_element>@style | tmp
    assert | tmp | <expected_style_value>
    

    path_to_element - 元素的 css 选择器

    例如,您可以使用 'width:100%' 来替换 expected_style_value

    【讨论】:

    • 哇,现在我好像明白了。你能描述一下,我怎么能检查部分匹配? assert on tmp with value top: 310px 失败:16:23:09`Actual value 'top: 310px; left: 20px; visibility: visible;' did not match 'top: 310px'。我尝试在值之前和之后添加星号(星号),但对我不起作用。
    • 我认为仅使用一个断言命令是不可能的。首先,您应该使用execute script,其中将比较结果 tmptop: 310px 保存在新变量中(或者您可以使用相同的变量),然后使用 @987654328 @ 将检查比较结果。
    • executeScript on n = tmp.indexOf("310px"); 失败:19:55:18 tmp 未定义
    • 这里我使用正则表达式查找样式并将结果保存在 tmp 变量executeScript | return /310px/.test(${tmp})| tmp
    猜你喜欢
    • 1970-01-01
    • 2022-01-04
    • 2019-04-30
    • 1970-01-01
    • 2020-07-09
    • 1970-01-01
    • 2013-09-20
    • 2011-07-04
    • 1970-01-01
    相关资源
    最近更新 更多