selenium登录测试例子

 

 

 

selenium登录测试例子_第1张图片

邮箱登录自动化案例:

from time import sleep
from selenium import webdriver

from moudle import Mail

driver = webdriver.Chrome()
driver.get("http://www.126.com")

mail = Mail(driver)
sleep(5)
#调用
mail.login()
'''
driver.switch_to.frame("iframe")
driver.find_element_by_id("username").clear()
driver.find_element_by_name("username").send_keys("admin")

driver.find_element_by_name("password").clear()
driver.find_element_by_name("password").send_keys("123456")

driver.find_element_by_id("login").click
'''
sleep(5)

#退出

mail.logout()
'''
driver.find_element_by_link_text("退出").click()
'''

driver.quit()

封装类:登录,退出

class Mail:
    def __init__(self,driver):
        self.driver = driver

    #登录:
    def login(self):
        driver.switch_to.frame("iframe")
        driver.find_element_by_id("username").clear()
        driver.find_element_by_name("username").send_keys("admin")

        driver.find_element_by_name("password").clear()
        driver.find_element_by_name("password").send_keys("123456")

        driver.find_element_by_id("login").click

    #退出:
    def logout(self):
        driver.find_element_by_link_text("退出").click()

参数:

selenium登录测试例子_第2张图片

 

调用:

selenium登录测试例子_第3张图片

 

 

 

 

你可能感兴趣的:(selenium)