【问题标题】:Java Selenium checking checkbox label statusJava Selenium 检查复选框标签状态
【发布时间】:2018-03-01 12:31:12
【问题描述】:

我正在做 Selenium 自动化应用程序,但我不知道如何检查复选框输入状态。也许有人也有这个问题?

这是 js+jquery 中的工作示例

$("input:checkbox").click(function() {
    console.log($(this).is(":checked"));
    if ($(this).is(":checked")) {
        //true
    } else {
        //false
    }
});

https://jsfiddle.net/67j8xhy0/3/

【问题讨论】:

    标签: java css html selenium input


    【解决方案1】:

    如果你真的想要你可以试试 xpath

    driver.findElement(By.xpath("//input[@type="checkbox")).isSelected()
    

    但如果你有复选框的 ID,你可以这样做

    driver.findElement(By.id("checkbox-id")).isSelected()
    

    这是文档:https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebElement.html#isSelected--

    【讨论】:

      【解决方案2】:

      您可以使用下面的代码,其中任何一个都可以,但最好我会使用几乎总是有效的 xpath:

      driver.findElement(By.xpath/id/csssector("enter your data")).isSelected();
      

      【讨论】:

      • 您的回答为尚未提及的话题带来了哪些新内容?
      猜你喜欢
      • 1970-01-01
      • 2017-03-01
      • 2010-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-09
      • 2016-10-29
      相关资源
      最近更新 更多