selenium登录163邮箱
datawhale-task5(selenium登录163邮箱)
1.selenium
如需控制 chrome
需要安装相对应 chromedriver
版本对应说明:
https://sites.google.com/a/chromium.org/chromedriver/downloads
http://npm.taobao.org/mirrors/chromedriver/
2.frameset
,frame
,iframe
的区别
参考资料:
https://blog.csdn.net/cjeric/article/details/79975712
https://blog.csdn.net/huilan_same/article/details/52200586
切图层 switch_to_frame(element)
发送文本 input_element.send_keys("string")
清空文本 input_element.clear()
完整代码
from selenium import webdriver
def main():
chrome = webdriver.Chrome("/home/yuge/Documents/developebin/chromedriver")
chrome.get("http://mail.163.com")
# 切换到 iframe
chrome.switch_to_frame(chrome.find_element_by_tag_name('iframe'))
# id 值是每次都换的
username = chrome.find_elements_by_xpath('//*[@id="auto-id-1551789133791"]')
password = chrome.find_elements_by_xpath('//*[@id="auto-id-1551789133794"]')
login = chrome.find_elements_by_xpath('//*[@id="dologin"]')
# 输入账号和密码
username.send_keys('1317****')
password.send_keys("*********")
login.click()
if __name__ == '__main__':
main()