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()

 

posted @ 2019-02-15 16:14  OTAKU_nicole  阅读(788)  评论(0编辑  收藏  举报