Selenium WebDriver-获取与切换浏览器窗口的句柄
通过selenium webdriver去切换浏览器的窗口,需要通过句柄,具体代码如下: # encoding=utf-8 import unittest import time import chardet from selenium import webdriver class VisitSogouByIE(unittest.TestCase): def setUp(self): # 启动chrome浏览器 self.driver = webdriver.Chrome(executable_path = " e:\\chromedriver " ) def test_operateWindowHandle(self): url = " http://www.baidu.com " self.driver.get(url) # 获取当前窗口句柄 now_handle = self.driver.current_window_handle # 打印当前获取的窗口句柄 print now_handle # 百度搜索输入框中输入“selenium” self.driver.find_element_by_id( " kw " ).send_keys( " w3cschool " ) # 点击搜索按钮 self.driver.find_element_by_id( " su " )