python 消息:没有此窗口:目标窗口已关闭

afdcj2ne  于 2023-02-18  发布在  Python
关注(0)|答案(2)|浏览(110)

如何切换到新打开的窗口?
我尝试了window name=,但我不知道如何获取窗口名称或自动切换到新打开的窗口,因为上一个窗口已自动关闭

try: #after first login, popup disapears
            wait = WebDriverWait(driver, 100)
            wait.until(EC.visibility_of_element_located((By.XPATH, '//*[@id="chakra-modal--header-1"]/button/svg/path')))
            driver.find_element(by = By.XPATH, value = '//*[@id="chakra-modal--header-1"]/button/svg/path').click() #exit pop-up
        except:
                pass
    
      
    
    #once in page
    
    #HERE I GOT THE ERROR

    wait = WebDriverWait(driver, 100)
    wait.until(EC.visibility_of_element_located((By.XPATH, '//*[@id="root"]/div[1]/div[1]/p')))
    elem = driver.find_element(by = By.XPATH, value = '//*[@id="root"]/div[1]/div[1]/p') #find balance element
yc0p9oo0

yc0p9oo01#

您可以找到所有打开的窗口/选项卡:

all_windows = driver.window_handles
print(all_windows) #to find windows IDs

你可以打开的窗口/选项卡的数量:

len(driver.window_handles)

要切换:

driver.switch_to.window(window_handle ID)
ldxq2e6h

ldxq2e6h2#

驱动程序。switch_to.window(window_handle ID)工作正常,谢谢

相关问题