Kaz*_*azi 4 python selenium webdriver webautomation selenium-webdriver
我正在尝试使用 Python selenium webdriver 切换到新打开的窗口。代码之前运行良好,但现在显示错误。令人惊讶的是,Python 无法识别 switch_to_window() 方法,并且没有可供访问的声明。
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])
Run Code Online (Sandbox Code Playgroud)
错误详情:
'WebDriver' object has no attribute 'switch_to_window'
Run Code Online (Sandbox Code Playgroud)
这个错误信息...
'WebDriver' object has no attribute 'switch_to_window'
Run Code Online (Sandbox Code Playgroud)
...意味着WebDriver对象不再支持属性switch_to_window()
switch_to_window在Selenium v2.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')