import traceback import time import unittest from idlelib import browser from selenium import webdriver from selenium.webdriver.common.by import By bro = webdriver.Chrome() # 1.打开浏览器 bro.maximize_window() # 最大化 bro.implicitly_wait(10) bro.get('https://mail.163.com/') # 2.输入网址 print('打开浏览器') time.sleep(4) #进入iframe,这是网页邮箱的通用框架 iframe=bro.find_element_by_xpath('//div[@id="loginDiv"]/iframe') bro.switch_to_frame(iframe) time.sleep(4) #输入账号 bro.find_element_by_name('email').clear() bro.find_element_by_name('email').send_keys('账号') time.sleep(1) #输入密码 bro.find_element_by_name('password').clear() bro.find_element_by_name('password').send_keys('s密码') time.sleep(1) #登录,切换回默认iframe bro.find_element_by_id('dologin').click() bro.switch_to_default_content() #判断登录是否成功 name=bro.find_element_by_id("spnUid").text print(name) if name=='账号': print("登录成功") else: print("登录失败")
标签:网易,name,登录,element,bro,自动,iframe,import,find From: https://www.cnblogs.com/haha1988/p/17234898.html