<tfoot id='jHJbV'></tfoot><legend id='jHJbV'><style id='jHJbV'><dir id='jHJbV'><q id='jHJbV'></q></dir></style></legend>
  1. <small id='jHJbV'></small><noframes id='jHJbV'>

        <bdo id='jHJbV'></bdo><ul id='jHJbV'></ul>
      <i id='jHJbV'><tr id='jHJbV'><dt id='jHJbV'><q id='jHJbV'><span id='jHJbV'><b id='jHJbV'><form id='jHJbV'><ins id='jHJbV'></ins><ul id='jHJbV'></ul><sub id='jHJbV'></sub></form><legend id='jHJbV'></legend><bdo id='jHJbV'><pre id='jHJbV'><center id='jHJbV'></center></pre></bdo></b><th id='jHJbV'></th></span></q></dt></tr></i><div id='jHJbV'><tfoot id='jHJbV'></tfoot><dl id='jHJbV'><fieldset id='jHJbV'></fieldset></dl></div>
    1. “NoSuchWindowException:没有这样的窗口:窗口已经关闭"通过 Python3 使用 Sel

      时间:2023-07-04

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

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

              <tfoot id='u4wwj'></tfoot>

                <bdo id='u4wwj'></bdo><ul id='u4wwj'></ul>

                <legend id='u4wwj'><style id='u4wwj'><dir id='u4wwj'><q id='u4wwj'></q></dir></style></legend>
                本文介绍了“NoSuchWindowException:没有这样的窗口:窗口已经关闭"通过 Python3 使用 Selenium 和 WebDriver 切换选项卡时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个表单,当我点击它时,它会在新选项卡中打开.当我尝试导航到该新选项卡时,我不断收到 NoSuchWindowException.代码非常简单.'myframe' 是新标签中的框架,信息最终会插入其中.我应该等待别的东西吗?

                I have a form that opens in a new tab when I click on it. When I try to navigate to that new tab, I keep getting a NoSuchWindowException. Code is pretty straightforward. 'myframe' is the frame within the new tab that the information will eventually get plugged into. Should I be waiting for something else?

                from selenium import webdriver
                from selenium.webdriver.support import expected_conditions as EC
                from selenium.webdriver.support.ui import WebDriverWait, Select
                from selenium.webdriver.common.by import By
                from selenium.common.exceptions import TimeoutException, NoSuchElementException
                import time
                import pandas as pd
                
                url = *****
                driver = webdriver.Chrome(executable_path = r'S:EngineeringJakeMasterControl Completing Pipette CalPM Formschromedriver')
                driver.get(url)
                
                wait = WebDriverWait(driver, 5)    
                
                window_before = driver.window_handles[0]
                driver.find_element_by_id('portal.scheduling.prepopulate').click()
                window_after = driver.window_handles[1]
                driver.switch_to_window(window_after)
                driver.switch_to_default_content()
                wait.until(EC.frame_to_be_available_and_switch_to_it('myframe'))
                

                <小时>

                Traceback (most recent call last):
                
                  File "<ipython-input-308-2aa72eeedd51>", line 1, in <module>
                    runfile('S:/Engineering/Jake/MasterControl Completing Pipette CalPM Forms/Pipette Completing CalPM Tasks.py', wdir='S:/Engineering/Jake/MasterControl Completing Pipette CalPM Forms')
                
                  File "C:ProgramDataAnaconda3libsite-packagesspyder_kernelscustomizespydercustomize.py", line 678, in runfile
                    execfile(filename, namespace)
                
                  File "C:ProgramDataAnaconda3libsite-packagesspyder_kernelscustomizespydercustomize.py", line 106, in execfile
                    exec(compile(f.read(), filename, 'exec'), namespace)
                
                  File "S:/Engineering/Jake/MasterControl Completing Pipette CalPM Forms/Pipette Completing CalPM Tasks.py", line 150, in <module>
                    create_new_cal_task(asset_number)
                
                  File "S:/Engineering/Jake/MasterControl Completing Pipette CalPM Forms/Pipette Completing CalPM Tasks.py", line 130, in create_new_cal_task
                    driver.switch_to_default_content()
                
                  File "C:ProgramDataAnaconda3libsite-packagesseleniumwebdriver
                emotewebdriver.py", line 783, in switch_to_default_content
                    self._switch_to.default_content()
                
                  File "C:ProgramDataAnaconda3libsite-packagesseleniumwebdriver
                emoteswitch_to.py", line 65, in default_content
                    self._driver.execute(Command.SWITCH_TO_FRAME, {'id': None})
                
                  File "C:ProgramDataAnaconda3libsite-packagesseleniumwebdriver
                emotewebdriver.py", line 314, in execute
                    self.error_handler.check_response(response)
                
                  File "C:ProgramDataAnaconda3libsite-packagesseleniumwebdriver
                emoteerrorhandler.py", line 242, in check_response
                    raise exception_class(message, screen, stacktrace)
                
                NoSuchWindowException: no such window: window was already closed
                  (Session info: chrome=68.0.3440.106)
                  (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 6.1.7601 SP1 x86_64)
                

                推荐答案

                感谢 Debanjan(并为迟到的回复道歉 - 刚回到办公室).我可以通过使用来解决这个问题

                Thanks Debanjan (and apologies for late response - just got back to office). I was able to fix this by using

                While True:
                    try:
                        [navigate to the new frame, wait for a specific element to show up]
                        break
                    except (NoSuchWindowException, NoSuchElementException):
                        pass
                

                我没有意识到,当我点击打开表单时,另一个窗口在后台非常短暂地打开,然后关闭.这将 window_handles 增加到 2,因此执行与等待 2 个窗口句柄相关的任何操作仍然会引发错误.

                I had not realized that when I clicked to open the form, another window opened very briefly in the background, and then closed. This increased the window_handles to 2, so doing anything relating to waiting for 2 window handles still kept throwing an error.

                这篇关于“NoSuchWindowException:没有这样的窗口:窗口已经关闭"通过 Python3 使用 Selenium 和 WebDriver 切换选项卡时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在 selenium 中不推荐使用 find_element_by_* 命令 下一篇:python, selenium中用于切换帧的函数

                相关文章

                  <bdo id='iTppH'></bdo><ul id='iTppH'></ul>

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

                  <legend id='iTppH'><style id='iTppH'><dir id='iTppH'><q id='iTppH'></q></dir></style></legend>
                    <tfoot id='iTppH'></tfoot>

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