from selenium import webdriver from time import sleep class TestWindows(): def setup(self): self.driver =webdriver.Chrome() self.driver.implicitly_wait(5) self.driver.maximize_window() def teardown(self): self.driver.quit() def test_window(self): self.driver.get("https://www.baidu.com/") sleep(3) self.driver.find_element_by_link_text("登录").click() print(self.driver.current_window_handle) sleep(3) self.driver.find_element_by_link_text("立即注册").click() print(self.driver.window_handles) window = self.driver.window_handles sleep(3) self.driver.switch_to_window(window[-1]) self.driver.find_element_by_id("TANGRAM__PSP_4__userName").send_keys("hjjjjj") sleep(3) self.driver.find_element_by_id("TANGRAM__PSP_4__phone").send_keys("123222") sleep(3) self.driver.find_element_by_id("TANGRAM__PSP_4__password").send_keys("passworf") sleep(3) self.driver.switch_to_window(window[0]) sleep(3) self.driver.find_element_by_id("TANGRAM__PSP_11__footerULoginBtn").click() sleep(3) print(self.driver.window_handles) print(self.driver.current_window_handle) self.driver.find_element_by_id("TANGRAM__PSP_11__userName").send_keys("hjj") sleep(3) self.driver.find_element_by_id("TANGRAM__PSP_11__password").send_keys("900000") sleep(3)