<tfoot id='Y4ynn'></tfoot>

    <i id='Y4ynn'><tr id='Y4ynn'><dt id='Y4ynn'><q id='Y4ynn'><span id='Y4ynn'><b id='Y4ynn'><form id='Y4ynn'><ins id='Y4ynn'></ins><ul id='Y4ynn'></ul><sub id='Y4ynn'></sub></form><legend id='Y4ynn'></legend><bdo id='Y4ynn'><pre id='Y4ynn'><center id='Y4ynn'></center></pre></bdo></b><th id='Y4ynn'></th></span></q></dt></tr></i><div id='Y4ynn'><tfoot id='Y4ynn'></tfoot><dl id='Y4ynn'><fieldset id='Y4ynn'></fieldset></dl></div>
      <bdo id='Y4ynn'></bdo><ul id='Y4ynn'></ul>

    1. <legend id='Y4ynn'><style id='Y4ynn'><dir id='Y4ynn'><q id='Y4ynn'></q></dir></style></legend>
    2. <small id='Y4ynn'></small><noframes id='Y4ynn'>

    3. 如何判断 Selenium for Java 中是否选中了一个复选框

      时间:2023-09-27
        <tbody id='Wc8LX'></tbody>
      • <legend id='Wc8LX'><style id='Wc8LX'><dir id='Wc8LX'><q id='Wc8LX'></q></dir></style></legend>

              <tfoot id='Wc8LX'></tfoot>

              <small id='Wc8LX'></small><noframes id='Wc8LX'>

                <bdo id='Wc8LX'></bdo><ul id='Wc8LX'></ul>
                <i id='Wc8LX'><tr id='Wc8LX'><dt id='Wc8LX'><q id='Wc8LX'><span id='Wc8LX'><b id='Wc8LX'><form id='Wc8LX'><ins id='Wc8LX'></ins><ul id='Wc8LX'></ul><sub id='Wc8LX'></sub></form><legend id='Wc8LX'></legend><bdo id='Wc8LX'><pre id='Wc8LX'><center id='Wc8LX'></center></pre></bdo></b><th id='Wc8LX'></th></span></q></dt></tr></i><div id='Wc8LX'><tfoot id='Wc8LX'></tfoot><dl id='Wc8LX'><fieldset id='Wc8LX'></fieldset></dl></div>
                本文介绍了如何判断 Selenium for Java 中是否选中了一个复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我在 Java 中使用 Selenium 来测试 webapp 中复选框的检查.代码如下:

                I am using Selenium in Java to test the checking of a checkbox in a webapp. Here's the code:

                private boolean isChecked;
                private WebElement e;
                

                我声明 e 并将其分配给复选框所在的区域.

                I declare e and assign it to the area where the checkbox is.

                isChecked = e.findElement(By.tagName("input")).getAttribute("checked").equals("true");
                

                奇怪的是 getAttribute("checked") 返回 null 并因此返回 NullPointerException

                What is weird is that getAttribute("checked") returns null and therefore a NullPointerException

                在复选框的 HTML 中,没有显示 checked 属性.但是,不是所有 input 元素都有一个 checked = true" 所以这段代码应该可以工作吗?

                In the HTML for the checkbox, there is no checked attribute displayed. However, isn't it the case that all input elements have a checked = "true" so this code should work?

                推荐答案

                如果您使用的是 Webdriver,那么您要查找的项目是 Selected.

                If you are using Webdriver then the item you are looking for is Selected.

                通常在复选框的渲染中,除非指定,否则实际上不会应用选中的属性.

                Often times in the render of the checkbox doesn't actually apply the attribute checked unless specified.

                所以你会在 Selenium Webdriver 中寻找的是这个

                So what you would look for in Selenium Webdriver is this

                isChecked = e.findElement(By.tagName("input")).Selected;
                

                由于WebDriver Java API中没有Selected,上面的代码应该如下:

                As there is no Selected in WebDriver Java API, the above code should be as follows:

                isChecked = e.findElement(By.tagName("input")).isSelected();
                

                这篇关于如何判断 Selenium for Java 中是否选中了一个复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Java 包导入别名 下一篇:如何从 Lucene TokenStream 中获取 Token?

                相关文章

                最新文章

                <tfoot id='6Pq3b'></tfoot>

                  <small id='6Pq3b'></small><noframes id='6Pq3b'>

                    <i id='6Pq3b'><tr id='6Pq3b'><dt id='6Pq3b'><q id='6Pq3b'><span id='6Pq3b'><b id='6Pq3b'><form id='6Pq3b'><ins id='6Pq3b'></ins><ul id='6Pq3b'></ul><sub id='6Pq3b'></sub></form><legend id='6Pq3b'></legend><bdo id='6Pq3b'><pre id='6Pq3b'><center id='6Pq3b'></center></pre></bdo></b><th id='6Pq3b'></th></span></q></dt></tr></i><div id='6Pq3b'><tfoot id='6Pq3b'></tfoot><dl id='6Pq3b'><fieldset id='6Pq3b'></fieldset></dl></div>

                  1. <legend id='6Pq3b'><style id='6Pq3b'><dir id='6Pq3b'><q id='6Pq3b'></q></dir></style></legend>
                    • <bdo id='6Pq3b'></bdo><ul id='6Pq3b'></ul>