selenium登錄163郵箱
datawhale-task5(selenium登錄163郵箱)
1.selenium如需控制 chrome 需要安裝相對(duì)應(yīng) chromedriver
版本對(duì)應(yīng)說明:
https://sites.google.com/a/chromium.org/chromedriver/downloads
http://npm.taobao.org/mirrors/chromedriver/
2.frameset,frame,iframe的區(qū)別
參考資料:
https://blog.csdn.net/cjeric/article/details/79975712
https://blog.csdn.net/huilan_same/article/details/52200586
切圖層 switch_to_frame(element)
發(fā)送文本 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"]')
# 輸入賬號(hào)和密碼
username.send_keys('1317****')
password.send_keys("*********")
login.click()
if __name__ == '__main__':
main()


浙公網(wǎng)安備 33010602011771號(hào)