• <small id='i902E'></small><noframes id='i902E'>

    <tfoot id='i902E'></tfoot>

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

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

        如何让 Selenium Web 驱动程序等待元素可访问,而不仅仅是存在?

        How can I get Selenium Web Driver to wait for an element to be accessible, not just present?(如何让 Selenium Web 驱动程序等待元素可访问,而不仅仅是存在?)

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

      2. <legend id='R9Alp'><style id='R9Alp'><dir id='R9Alp'><q id='R9Alp'></q></dir></style></legend>

            <tbody id='R9Alp'></tbody>

              • <tfoot id='R9Alp'></tfoot>
                <i id='R9Alp'><tr id='R9Alp'><dt id='R9Alp'><q id='R9Alp'><span id='R9Alp'><b id='R9Alp'><form id='R9Alp'><ins id='R9Alp'></ins><ul id='R9Alp'></ul><sub id='R9Alp'></sub></form><legend id='R9Alp'></legend><bdo id='R9Alp'><pre id='R9Alp'><center id='R9Alp'></center></pre></bdo></b><th id='R9Alp'></th></span></q></dt></tr></i><div id='R9Alp'><tfoot id='R9Alp'></tfoot><dl id='R9Alp'><fieldset id='R9Alp'></fieldset></dl></div>
                  <bdo id='R9Alp'></bdo><ul id='R9Alp'></ul>
                • 本文介绍了如何让 Selenium Web 驱动程序等待元素可访问,而不仅仅是存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在为 Web 应用程序编写测试.一些命令会弹出对话框,这些对话框具有可见的控件,但有一段时间不可用.(它们是灰色的,但 webdriver 仍然认为它们是可见的).

                  I am writing tests for a web application. Some commands pull up dialog boxes that have controls that are visible, but not available for a few moments. (They are greyed out, but webdriver still sees them as visible).

                  我如何告诉 Selenium 等待元素实际可访问,而不仅仅是可见?

                  How can I tell Selenium to wait for the element to be actually accessible, and not just visible?

                      try:
                          print "about to look for element"
                          element = WebDriverWait(driver, 10).until(lambda driver : driver.find_element_by_id("createFolderCreateBtn"))
                          print "still looking?"
                      finally: print 'yowp'
                  

                  这是我尝试过的代码,但它在按钮可用之前看到"按钮,并且基本上在假定的等待"之后收费.

                  Here is the code that I have tried, but it "sees" the button before it is usable and basically charges right past the supposed "wait".

                  请注意,我可以在代码中填充 10 秒的睡眠时间,而不是这样,代码会正常工作,但这是丑陋、不可靠且效率低下的.但它确实证明了问题只是点击"命令在控件的可用性之前竞争.

                  Note that I can stuff a ten second sleep into the code instead of this and the code will work properly, but that is ugly, unreliable, and inefficient. But it does prove that the problem is just that "click" command is racing ahead of the availability of the controls.

                  推荐答案

                      print time.time()
                      try:
                          print "about to look for element"
                          def find(driver):
                              e = driver.find_element_by_id("createFolderCreateBtn")
                              if (e.get_attribute("disabled")=='true'):
                                  return False
                              return e
                          element = WebDriverWait(driver, 10).until(find)
                          print "still looking?"
                      finally: print 'yowp'
                      print "ok, left the loop"
                      print time.time()
                  

                  这就是我们最终的结果.(感谢 lukeis 和 RossPatterson.)请注意,我们必须按 id 查找所有项目,然后按禁用"过滤.我更喜欢单一的搜索模式,但你能做什么?

                  Here is what we ended up with. (Thanks to lukeis and RossPatterson.) Note that we had to find all the items by id and then filter by "disabled". I would have preferred a single search pattern, but what can you do?

                  这篇关于如何让 Selenium Web 驱动程序等待元素可访问,而不仅仅是存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  env: python: No such file or directory(env: python: 没有这样的文件或目录)
                  How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                  Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                  Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                  Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                  When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)

                • <tfoot id='QbJiF'></tfoot>

                  <legend id='QbJiF'><style id='QbJiF'><dir id='QbJiF'><q id='QbJiF'></q></dir></style></legend>

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

                          • <small id='QbJiF'></small><noframes id='QbJiF'>