废话不多少,全在代码注释中
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/3/5 9:00
# @Author : StalloneYang
# @File : 05_selenium_163.py
# @desc:
from selenium import webdriver
import time
web = webdriver.Chrome()
web.get("https://mail.163.com/")
web.maximize_window()
web.implicitly_wait(5)
web.switch_to.frame(web.find_element_by_xpath("//iframe[starts-with(@id,'x-URS-iframe')]")) # iframe是第一个大坑,必须切入才行,第二大坑是这个iframe的id是动态的,直接搞死初学者,解决办法是用starts-with
time.sleep(1)
web.find_element_by_xpath("//input[starts-with(@id,'auto-id-')]").clear()
time.sleep(1)
web.find_element_by_xpath("//input[starts-with(@id,'auto-id-')]").send_keys("yangqinglong518")
time.sleep(1)
web.find_element_by_xpath("//input[starts-with(@placeholder,'输入密码')]").clear()
time.sleep(1)
web.find_element_by_xpath("//input[starts-with(@placeholder,'输入密码')]").send_keys("**********")
time.sleep(1)
web.find_element_by_xpath('//*[@id="dologin"]').click()
time.sleep(3)
web.close()