Python small ejercicio-9 Selenium webdriver login 126 buzón de correo

from selenium import webdriver
from selenium.webdriver import ActionChains
import time

class MyApplicationTest(object):
	def __init__(self):
		self.driver = webdriver.Firefox()

	def MyApplicationLogin(self,url,name,pwd):
		#driver = webdriver.Firefox()
		print("开始1")
		#url = 'https://mail.126.com/'
		self.driver.get(url)
		print("开始2")
		ifr = self.driver.find_element_by_xpath("//iframe[@frameborder=0]")
		time.sleep(1)
		self.driver.switch_to_frame(ifr)
		print("定位到iframe")
		el = self.driver.find_element_by_xpath("""//*[@data-placeholder="邮箱帐号或手机号码"]""")# 通过xpath来定位用户名输入框  //*[@data-placeholder="邮箱帐号或手机号码"]
		print("开始3")
		el.send_keys(name)# 向定位的用户名输入框传入用户名
		el01 = self.driver.find_element_by_css_selector("[data-placeholder=输入密码]")# 通过css来定位密码输入框
		print("开始3")
		el01.send_keys(pwd)# 向定位的密码输入框传入密码
		btn = self.driver.find_element_by_css_selector("#dologin")
		btn.click()
		time.sleep(1)
		newurl = self.driver.current_url
		return newurl
	
if __name__ == "__main__":	
	url = 'https://mail.126.com/'
	namelist= [此处填写账号名]
	pwdlist = [此处填写密码]
	po = 0
	while po<len(namelist):
		name = namelist[po]
		pwd = pwdlist[po]
		mapp = MyApplicationTest()
		newurl = mapp.MyApplicationLogin(url,name,pwd)
		time.sleep(2)
		po+=1

Supongo que te gusta

Origin blog.csdn.net/KathyLJQ/article/details/109720745
Recomendado
Clasificación