切换窗口
# 这是切换到新窗口 def switch_new_window(): try: new_window = driver.window_handles[-1] driver.switch_to.window(new_window) except Exception as e: raise e # 跳到默认的frame def switch_to_default(): try: driver.switch_to.default_content() print("已切回默认frame") except Exception as e: raise e # 切换浏览器窗口句柄 def switch_to_window(locator): try: h = driver.current_window_handle print(h) all_h = driver.window.handles driver.switch_to.window(all_h[locator]) except Exception as e: raise e # 切换到frame里面 def switch_to_frame(by, locator): try: driver.switch_to.frame(get_element(driver, by, locator)) print("切换frame成功") except Exception as e: raise e
心之所向无人可挡