讲三个方法
driver.switch_to.frame("第一个iframe标签属性值")
driver.switch_to.frame(" 第二个iframe标签属性值")
driver.switch_to.parnet_frame() 切换回第一个iframe页面
driver.switch_to.default_content() 切换回主文档
1 from selenium import webdriver 2 from time import sleep 3 4 driver = webdriver.Firefox() 5 driver.get("http://www.gdhuida1688.com/crm_index/index") 6 sleep(2) 7 driver.find_element_by_id('username').send_keys('huida') 8 driver.find_element_by_id('password').send_keys('huida168') 9 driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[2]/form/div[3]/button').click() 10 sleep(2) 11 12 driver.find_element_by_xpath("/html/body/div[1]/div/div[1]/div[3]/div[3]/span[2]").click() 13 sleep(1) 14 driver.find_element_by_xpath('/html/body/div[4]/div[2]/div/a[1]').click() 15 sleep(3) 16 17 # iframe = driver.find_element_by_css_selector('#my_iframe') 18 '''切换进第一个iframe''' 19 driver.switch_to.frame('my_iframe') 20 21 driver.find_element_by_xpath("//div[@class='body_header']/form/div[3]/div[1]/a").click() 22 sleep(3) 23 24 '''切换进第二个iframe''' 25 driver.switch_to.frame('layui-layer-iframe1') 26 driver.find_element_by_css_selector("input[name='name']").send_keys('project') 27 28 '''切换回第一个iframe''' 29 driver.switch_to.parent_frame() 30 31 '''切换回主文档''' 32 driver.switch_to.default_content() 33 34 sleep(2) 35 driver.quit()