# ifame 框架切换
# 知识点:切换框架 driver.switch_to.frame(id & name),返回默认框架:driver.switch_to.default_content()
# 熟悉使用By来定位元素 CSS_SELECTOR和XPATH
import time
from selenium.webdriver.common.by import By
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('E:pythonhtml\frame\frame.html')
driver.maximize_window()
driver.implicitly_wait(10)
# 顶部的框架
driver.switch_to.frame('top')
driver.find_element(By.CSS_SELECTOR,'input').send_keys('欢迎来到天堂')
time.sleep(2)
driver.switch_to.default_content()
# 左边的框架
driver.switch_to.frame('left')
driver.find_element(By.CSS_SELECTOR,'input').send_keys('臭仙女')
time.sleep(2)
driver.switch_to.default_content()
# 主框架main
driver.switch_to.frame('main')
driver.find_element(By.CSS_SELECTOR,'input').send_keys('jasonchenYT的臭仙女')
time.sleep(2)
driver.switch_to.default_content()
# 框架没有id或者name时,自定义框架名
# iframe = driver.find_element(By.CSS_SELECTOR,'定位元素信息')
# driver.switch_to.frame(iframe)
time.sleep(3)
driver.close()