• <legend id='ZYRIT'><style id='ZYRIT'><dir id='ZYRIT'><q id='ZYRIT'></q></dir></style></legend>
  • <small id='ZYRIT'></small><noframes id='ZYRIT'>

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

        <tfoot id='ZYRIT'></tfoot>

        用于处理弹出浏览器窗口的 Python webdriver 不是警报

        Python webdriver to handle pop up browser windows which is not an alert(用于处理弹出浏览器窗口的 Python webdriver 不是警报)

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

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

            <tfoot id='fLbsm'></tfoot>

                  <tbody id='fLbsm'></tbody>
                <i id='fLbsm'><tr id='fLbsm'><dt id='fLbsm'><q id='fLbsm'><span id='fLbsm'><b id='fLbsm'><form id='fLbsm'><ins id='fLbsm'></ins><ul id='fLbsm'></ul><sub id='fLbsm'></sub></form><legend id='fLbsm'></legend><bdo id='fLbsm'><pre id='fLbsm'><center id='fLbsm'></center></pre></bdo></b><th id='fLbsm'></th></span></q></dt></tr></i><div id='fLbsm'><tfoot id='fLbsm'></tfoot><dl id='fLbsm'><fieldset id='fLbsm'></fieldset></dl></div>
                  <bdo id='fLbsm'></bdo><ul id='fLbsm'></ul>
                  本文介绍了用于处理弹出浏览器窗口的 Python webdriver 不是警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在开发一个 Web 应用程序,其中单击某个链接会出现另一个弹出窗口.弹出窗口不是警报,而是一个包含各种字段的表单,用户可以输入并单击下一步".

                  I am working on a web application, in which clicking on some link another popup windows appears. The pop windows is not an alert but its a form with various fields to be entered by user and click "Next".

                  如何使用 selenium 处理/自动化这个弹出窗口.

                  How can I handle/automate this popup windows using selenium.

                  总结:-

                  1. 点击超链接(网址)-点击这里"
                  2. 用户注册表单显示为弹出窗口
                  3. 一个数据由用户填写
                  4. 点击下一步/提交按钮.
                  5. 另一个下一个重定向到另一个页面/表单用户个人信息页面"
                  6. 个人信息由用户填写
                  7. 点击下一步/提交"
                  8. 弹出窗口消失了.
                  9. 现在对原始/基本页面进行进一步处理.

                  推荐答案

                  切换到弹出窗口具有挑战性,至少有两个不同的原因:

                  Switching to a popup is challenging for at least two separate reasons:

                  1. 很多人都知道的,就是在弹窗出现的时候需要同时使用driver.switch_to.window(window_handle),这样才能在弹窗中找到元素,和弹出窗口关闭后,您可以在主窗口中找到元素.
                  2. 只有机器慢的人可能会遇到的情况,就是当 Selenium 将窗口句柄作为变量提供时,它最初设置为 None,并且需要一点时间才能填充一个值.
                  1. The one that many people know, which is that you need to use driver.switch_to.window(window_handle) both when the popup appears, so that you can find elements in the popup window, and after the popup is closed, so that you can find elements back in the main window.
                  2. The one that only people with slow machines are likely to encounter, which is that when Selenium makes a window handle available as a variable, it's initially set to None, and takes a little while before it's filled in with a value.

                  这里有一些代码可以在执行您请求的序列时解决这些问题.我省略了 import 语句,并且使用了我希望显而易见的变量名.另外,请注意,我喜欢在我的代码中使用 find_element(s)_by_xpath;随意使用其他 find_element(s)_by 方法:

                  Here's some code that addresses those issues while carrying out your requested sequence. I'm leaving out the import statements, and I'm using variable names that I hope are obvious. Also, note that I like to use find_element(s)_by_xpath in my code; feel free to use other find_element(s)_by methods:

                  main_window_handle = None
                  while not main_window_handle:
                      main_window_handle = driver.current_window_handle
                  driver.find_element_by_xpath(u'//a[text()="click here"]').click()
                  signin_window_handle = None
                  while not signin_window_handle:
                      for handle in driver.window_handles:
                          if handle != main_window_handle:
                              signin_window_handle = handle
                              break
                  driver.switch_to.window(signin_window_handle)
                  driver.find_element_by_xpath(u'//input[@id="id_1"]').send_keys(user_text_1)
                  driver.find_element_by_xpath(u'//input[@value="OK"]').click()
                  driver.find_element_by_xpath(u'//input[@id="id_2"]').send_keys(user_text_2)
                  driver.find_element_by_xpath(u'//input[@value="OK"]').click()
                  driver.switch_to.window(main_window_handle) #or driver.switch_to_default_content()
                  

                  如果有人(可能是我)需要在示例中添加更多内容或提供其他信息以使其更清晰,请告诉我.

                  Please let me know if someone (maybe me) needs to add more to the example, or provide other info, to make it more clear.

                  这篇关于用于处理弹出浏览器窗口的 Python webdriver 不是警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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% 就足够了)

                  <small id='5tAtP'></small><noframes id='5tAtP'>

                    <tbody id='5tAtP'></tbody>
                      <tfoot id='5tAtP'></tfoot>

                      • <legend id='5tAtP'><style id='5tAtP'><dir id='5tAtP'><q id='5tAtP'></q></dir></style></legend>

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

                            <bdo id='5tAtP'></bdo><ul id='5tAtP'></ul>