【问题标题】:cypress doesn't recognize the element I'm trying to find by placeholder赛普拉斯无法识别我试图通过占位符查找的元素
【发布时间】:2021-10-06 08:38:05
【问题描述】:

元素:

我是如何识别的:
cy.get("input[placeholder=What's this article about?]").type("
错误:
语法错误,无法识别的表达式:input[placeholder=这篇文章是关于什么的?]

【问题讨论】:

    标签: javascript automated-tests cypress


    【解决方案1】:

    试试这个:

    cy.get("input[placeholder=\"What's this article about?\"]").type("<3");
    

    或者这个少转义字符:

    cy.get('input[placeholder="What\'s this article about?"]').type("<3");
    

    【讨论】:

      【解决方案2】:

      另一种方法是使用[attribute*=value] 选择器。这将选择其属性值包含原始字符串的子字符串的每个元素。所以在你的情况下它可能是[placeholder*="article"][placeholder*="article about"],基本上你可以添加任何你想要的子字符串。

      注意事项 - 仅当您确定要搜索的子字符串出现一次,即您的目标元素时,才应使用此选项。

      cy.get('input[placeholder*="article about"]').type('<3')
      

      或者,如果您有多次出现,那么您必须使用 eq 才能到达该元素。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-12-23
        • 2020-12-23
        • 1970-01-01
        • 1970-01-01
        • 2019-06-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多