【问题标题】:How to locate the checkboxes with the attribute checked如何找到选中属性的复选框
【发布时间】:2019-02-14 09:55:57
【问题描述】:

我有一个复选框列表,我需要找到具有“已选中”属性的复选框。下面是我的复选框元素的外观,

<input type="checkbox" class="u-display--inline-block u-margin-right--small" checked="">

如何使用 xpath 找到它?我不能使用 //input[@type='checkbox' 和 @checked='true')] 因为我没有检查值 true 属性。任何建议将不胜感激。

【问题讨论】:

    标签: selenium selenium-webdriver xpath checkbox css-selectors


    【解决方案1】:

    您可以只提及属性checked 来测试它是否存在:

    //input[@type='checkbox' and @checked]
    

    【讨论】:

      【解决方案2】:

      要查找具有checked 属性的复选框,您可以使用以下任一解决方案:

      • cssSelector

        "input.u-display--inline-block.u-margin-right--small[type='checkbox'][checked]"
        
      • xpath

        "//input[@class='u-display--inline-block u-margin-right--small' and @type='checkbox'][@checked]"
        

      【讨论】:

        【解决方案3】:

        请使用下面的 xpath 进行相同的操作:

        //input[@type='checkbox'  and @checked]
        

        【讨论】:

          猜你喜欢
          • 2015-05-19
          • 2014-06-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-11-13
          • 2014-11-24
          • 1970-01-01
          相关资源
          最近更新 更多