解决办法,跳转到崩溃网页后,使用WebDriverWait
# coding=utf-8
from selenium import webdriver
from time import sleep
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
#跳转到崩溃网页
driver.window_handles[-1] # 1.获取当前页面(跳转过来的页面)句柄:
driver.switch_to.window(driver.window_handles[-1]) # 2.切换窗口:
sleep(3)
# 获取当前页面(跳转过来的页面)链接
try:
# 等待新页面URL加载完成
new_page_url = WebDriverWait(driver, 7).until(EC.url_changes(driver.current_url))
print(new_page_url)
except Exception as e:
print(f"An exception occurred: {e}")
finally:
driver.close() # 关闭第二个窗口,切换到第一个窗口
print('成功')