标签:bdr iframe title email 参数 需要 selenium pre rom
mail126.py脚本如下
from selenium import webdriver from time import sleep from model1 import Login driver = webdriver.Chrome() driver.get("http://www.126.com") print("登录前") title = driver.title print("title:" + title) #调用登录 l = Login(driver) #邮箱用户名需输入你自己的真实的126邮箱用户名,密码也需要是真实的 l.login("邮箱用户名","邮箱密码") url = driver.current_url print("url:"+url) sleep(5) print("登陆后:") title = driver.title print("url:"+url) text = driver.find_element_by_id("spnUid").text print("user name:"+text) #断言 assert text == "邮箱用户名"
model1.py脚本如下
class Login(): def __init__(self,driver): self.driver = driver def login(self,username,password): driver = self.driver driver.switch_to.frame("x-URS-iframe") driver.find_element_by_name("email").clear() driver.find_element_by_name("email").send_keys(username) driver.find_element_by_name("password").clear() driver.find_element_by_name("password").send_keys(password) driver.find_element_by_id("dologin").click()
标签:bdr iframe title email 参数 需要 selenium pre rom
原文地址:http://www.cnblogs.com/lza945/p/7158664.html