import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("http://i.qq.com/")
try:
driver.find_element_by_id('login_div')
a = True
except:
a = False
if a == True:
driver.switch_to.frame('login_frame')
driver.find_element_by_id('switcher_plogin').click()
driver.find_element_by_id('u').clear()#选择用户名框
driver.find_element_by_id('u').send_keys('QQ')
driver.find_element_by_id('p').clear()
driver.find_element_by_id('p').send_keys('password')
driver.find_element_by_id('login_button').click()
time.sleep(3)
print(driver.page_source)
driver.close()
一开始直接找登陆的账号密码Element
但是却报错显示未查找到该Element
于是打印了下 page_source,查了下view-page
发现的确未有改元素
拜读了大佬的博客才知道这里使用了iframe加载了登陆框
然后就是定位该框,点击账号密码登录输入,点击登陆即可