python自动化测试——iframe切换
from selenium import webdriver driver = webdriver.Chrome() driver.get("https://www.***.cn") #有id的,用id定位,id=iframe1 driver.switch_to.frame("iframe1") #无id的,用index索引定位,index=1 driver.switch_to.frame(1)
# 啥都没的元素定位,先找到iframe
iframe_loc = (By.CSS_SELECTOR,"***")
ele = driver.find_element(iframe_loc)
driver.switch_to.frame(ele) # 切换到iframe
#切换回默认 driver.switch_to.default_content() driver.quit()
本文来自博客园,作者:OTAKU_nicole,转载请注明原文链接:https://www.cnblogs.com/nicole-zhang/p/10384242.html