1. <legend id='nLJSP'><style id='nLJSP'><dir id='nLJSP'><q id='nLJSP'></q></dir></style></legend>
    <tfoot id='nLJSP'></tfoot>

  2. <small id='nLJSP'></small><noframes id='nLJSP'>

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

      使用 Selenium Webdriver 测试元素是否聚焦

      Test if an element is focused using Selenium Webdriver(使用 Selenium Webdriver 测试元素是否聚焦)

        <tbody id='HFh2H'></tbody>

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

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

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

                本文介绍了使用 Selenium Webdriver 测试元素是否聚焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我真的很惊讶我在互联网上找不到使用 Selenium Webdriver 测试元素焦点的参考资料.

                I'm really surprised I can't find references on the internet to testing for element focus using Selenium Webdriver.

                我想检查何时尝试提交表单而遗漏了必填字段,焦点移至空字段.但我看不到任何使用 WebDriver API 的方法.

                I'm wanting to check when when a form submission is attempted with a mandatory field missed, focus is moved to the empty field. But I cannot see any way to do this using the WebDriver API.

                我将能够使用 JavascriptExecutor.但是阅读 FAQ 让我觉得一定有某种方法可以使用驱动程序本身来执行检查.

                I will be able to find the focused element using a JavascriptExecutor. But reading the FAQ makes me think there must be some way to perform the check using the driver itself.

                感谢您的帮助.

                推荐答案

                driver.switchTo().activeElement() 将返回当前聚焦的WebElement.WebElement 已经很好地定义了相等性,因此您可以调用 element.equals(driver.switchTo().activeElement()).

                driver.switchTo().activeElement() will return the currently focused WebElement. Equality is well defined for WebElement, so you can call element.equals(driver.switchTo().activeElement()).

                调用有点误导性的名为driver.switchTo().activeElement()实际上并没有切换焦点,driver.findElement()也没有,所以你没有需要在 switchTo().defaultContent() 之后;事实上,这样做可能会模糊当前元素.

                Calling the slightly misleading named driver.switchTo().activeElement() does not in fact switch focus, neither does driver.findElement(), so you do not need to switchTo().defaultContent() after; in fact, doing so would probably blur the current element.

                这篇关于使用 Selenium Webdriver 测试元素是否聚焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                C# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                IBM .NET Data Provider Connection String issue with Library List(库列表的 IBM .NET 数据提供程序连接字符串问题)
                .NET DB2 OLEDB pre-requisites(.NET DB2 OLEDB 先决条件)
                Referring to Code in IBM.Data.DB2 makes that Assembly Unavailable to the rest of my Solution(引用 IBM.Data.DB2 中的代码使该程序集对我的解决方案的其余部分不可用)
                • <bdo id='MRdha'></bdo><ul id='MRdha'></ul>

                    <tfoot id='MRdha'></tfoot>

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

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