我正在嘗試使用 Python selenium webdriver 切換到新打開的視窗。該代碼以前運行良好,但現在顯示錯誤。令人驚訝的是,switch_to_window() 方法沒有被 Python 識別,也沒有宣告可轉。
def process_ebl_statements(self, account_number):
current_window = self.driver.current_window_handle
all_windows = self.driver.window_handles
print("Current window: ", current_window)
print("All windows: ", all_windows)
number_of_windows = len(all_windows)
self.driver.switch_to_window(all_windows[number_of_windows - 1])
錯誤詳情:
'WebDriver' object has no attribute 'switch_to_window'

uj5u.com熱心網友回復:
這個錯誤資訊...
'WebDriver' object has no attribute 'switch_to_window'
...暗示WebDriver物件不再支持屬性switch_to_window()
切換到視窗
switch_to_window在Selenium v??2.41 中被棄用:
硒 2.41
- 棄用 switch_to_* 而支持 driver.switch_to.*
因此,您會看到錯誤。
解決方案
而不是switch_to_window您需要使用switch_to。
例子:
driver.switch_to.active_elementdriver.switch_to.alertdriver.switch_to.default_content()driver.switch_to.frame()driver.switch_to.parent_frame()driver.switch_to.window('main')
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/381780.html
標籤:Python 硒 硒网络驱动程序 网络驱动程序 网络自动化
