切换iframe的方式

时间:2020-06-05 16:20:31   收藏:0   阅读:42
 1 from selenium import webdriver
 2 from time import sleep
 3 from selenium.webdriver.support.wait import WebDriverWait
 4 from selenium.webdriver.support import expected_conditions as EC
 5 
 6 driver = webdriver.Firefox()
 7 driver.get("https://ke.qq.com/")
 8 driver.implicitly_wait(20)
 9 driver.maximize_window()
10 
11 driver.find_element_by_id("js_login").click()
12 
13 driver.find_element_by_xpath(//div[@class="content-btns"]/a[1]).click()
14 # 方法一# 切换ifame=进入到另一个html
15 driver.switch_to.frame("login_frame_qq")
16 # 方法二
17 # driver.switch_to.frame(driver.find_element_by_xpath("//iframe[@name=‘login_frame_qq‘]"))
18 # 方法三  EC.frame_to_be_available_and_switch_to_it
19 # WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it("login_frame_qq"))
20 driver.find_element_by_id(switcher_plogin).click()
21 # 回到默认画面
22 driver.switch_to.default_content()
23 sleep(0.5)
24 driver.quit()

 

原文:https://www.cnblogs.com/albeexu/p/13049709.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!