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

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

      <tfoot id='u3puw'></tfoot>
    2. Selenium WebDriver 点击隐藏元素

      时间:2023-10-12

      • <legend id='yRfh8'><style id='yRfh8'><dir id='yRfh8'><q id='yRfh8'></q></dir></style></legend>

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

            <tfoot id='yRfh8'></tfoot>
            • <bdo id='yRfh8'></bdo><ul id='yRfh8'></ul>

                <tbody id='yRfh8'></tbody>
              • <small id='yRfh8'></small><noframes id='yRfh8'>

              • 本文介绍了Selenium WebDriver 点击隐藏元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                您好,我想知道如何使用 Selenium WebDriver 点击隐藏元素和/或禁用元素.

                Hi I would like to know how to click on hidden element and/or disable element by using Selenium WebDriver.

                我知道使用 selenium 1 我可以这样做:

                I know with selenium 1 I can do this as below:

                selenium.click(id="idOfHiddenField");
                

                这会起作用,但是对于 selenium 2 (WebDriver),这不起作用.我不想使用 jquery 来启用或显示隐藏字段或 JavaScript.这是因为大部分测试都使用 xpath.

                and this would work, but with selenium 2 (WebDriver), this doesn't. I do not want to use jquery to enable or show hidden fields , or JavaScript. This is because most of the test are using xpath.

                还是我只需要使用旧的 selenium,它允许您点击隐藏字段?

                Or do I just have to stay with old selenium which allows you to click on hidden fields?

                推荐答案

                有一种更简单的方法可以使用 JavascriptExecutor 解决该问题.

                There is a easier way to work around the problem using JavascriptExecutor.

                例如:

                document.getElementsByClassName('post-tag')[0].click();
                

                上面的 javascript 会点击此页面右上角的Selenium"标签(在您的问题旁边),即使它被隐藏(假设地).

                The above javascript would click on the "Selenium" tag on the top right of this page (next to your question), even if it were hidden (hypothetically).

                您需要做的就是通过 JavascriptExecutor 接口发出这条 JS 指令,如下所示:

                All you need to do is issue this JS instruction via the JavascriptExecutor interface like so:

                (JavascriptExecutor(webdriver)).executeScript("document.getElementsByClassName('post-tag')[0].click();");
                

                这将使用 JS 沙箱和合成点击事件来执行点击操作.虽然它违背了 WebDriver 用户活动模拟的目的,但您可以在小众场景中使用它,例如在您的案例中取得良好效果.

                This would use the JS sandbox and synthetic click event to perform the click action. Although it defeats the purpose of WebDriver user activity simulation, you can use it in niche scenarios like in your case to good effect.

                这篇关于Selenium WebDriver 点击隐藏元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:通过 Selenium 和 Python 通过 WebDriver 实例调用 exec 下一篇:无法使用 selenium webdriver 的 gettext() 从文本框中读

                相关文章

                最新文章

                <tfoot id='L0gdo'></tfoot>

              • <i id='L0gdo'><tr id='L0gdo'><dt id='L0gdo'><q id='L0gdo'><span id='L0gdo'><b id='L0gdo'><form id='L0gdo'><ins id='L0gdo'></ins><ul id='L0gdo'></ul><sub id='L0gdo'></sub></form><legend id='L0gdo'></legend><bdo id='L0gdo'><pre id='L0gdo'><center id='L0gdo'></center></pre></bdo></b><th id='L0gdo'></th></span></q></dt></tr></i><div id='L0gdo'><tfoot id='L0gdo'></tfoot><dl id='L0gdo'><fieldset id='L0gdo'></fieldset></dl></div>
                • <bdo id='L0gdo'></bdo><ul id='L0gdo'></ul>
                1. <legend id='L0gdo'><style id='L0gdo'><dir id='L0gdo'><q id='L0gdo'></q></dir></style></legend>

                  1. <small id='L0gdo'></small><noframes id='L0gdo'>