【问题标题】:Way to find element by style?按样式查找元素的方法?
【发布时间】:2022-06-29 02:19:56
【问题描述】:

HTML: <div class="example-event Gantt-event event_class_color Gannt-event-another-edit" data-object-type-id="4" data-is-people="true" data-is-taken="false" data-is-externalorder="false" data-is-inaccessibility="false" data-work-status="1" title="SEPP-16288" style="width: 400px; height: 18px; left: 400px; top: 5px; line-height: 18px; background: repeating-linear-gradient(45deg, rgb(255, 243, 204), rgb(255, 243, 204) 10px, rgb(249, 30, 26) 10px, rgb(249, 30, 26) 20px);"></div>

我有几个相同的元素,但风格不同。赛普拉斯有什么方法可以按样式选择元素,但版本比: cy.get('[style="width: 400px; height: 18px; left: 400px; top: 5px; line-height: 18px; background: repeating-linear-gradient(45deg, rgb(255, 243, 204), rgb(255, 243, 204) 10px, rgb(249, 30, 26) 10px, rgb(249, 30, 26) 20px);"]') ?例如只使用背景颜色或高度?

【问题讨论】:

  • 你有几个data 属性。如果他们不改变每次运行,您可以使用这些吗?

标签: cypress


【解决方案1】:

您可以使用*cy.get('[style= 像这样cy.get('[style*= 进行包含搜索。

cy.get('[style*="background: repeating-linear-gradient(45deg, rgb(255, 243, 204)"]')

话虽如此,在做这样的选择器之前,我会尝试其他方法来定位您的元素。您是否尝试过定位父元素并执行within( ($el) => {})。通过这种方式,您可以将可以找到的元素限制在有限数量的元素中,通常允许您使用更详细的选择器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-30
    • 1970-01-01
    • 2022-11-05
    • 2013-01-12
    • 2018-05-31
    • 1970-01-01
    • 2013-12-03
    • 1970-01-01
    相关资源
    最近更新 更多