码迷,mamicode.com
首页 > 其他好文 > 详细

selenium之封装登陆操作

时间:2017-07-31 22:58:17      阅读:395      评论:0      收藏:0      [点我收藏+]

标签:window   cli   pass   初始化   highlight   win   files   _id   chrome   

 

# selenium 封装登录操作举例
import os, time


# from selenium import webdriver

class LoginPage():
    ‘‘‘登录模块‘‘‘

    def __init__(self, path=‘‘):
        ‘‘‘初始化加载驱动‘‘‘
        if path:
            chrome_path = path
        else:
            chrome_path = "C:\\Users\\nriet\AppData\Local\Google\Chrome\Application\chrome.exe"
        os.environ["webdriver.chrome.bin"] = os.path.abspath(chrome_path)  # 浏览器安装路径
        self.driver_path = "D:\\Program Files\\Python36\\chromedriver.exe"  # 驱动路径
        # self.driver = webdriver.Chrome(executable_path=self.driver_path)
        self.driver = ‘‘

    def login(self, driver):
        ‘‘‘登录操作‘‘‘
        self.driver = driver
        self.driver.get("http://192.168.20.179:8080/YZWXTQ/login.do")
        time.sleep(1)
        self.driver.maximize_window()
        self.driver.find_element_by_id(‘name‘).send_keys(‘username‘)
        self.driver.find_element_by_id(‘password‘).send_keys(‘password‘)
        self.driver.find_element_by_id(‘login-btn‘).click()
        time.sleep(1)
        return self.driver

    def set_driver(self, driver):
        self.driver = driver

    def get_driver(self):
        return self.driver

    def quit(self):
        time.sleep(2)
        self.driver.quit()

 

selenium之封装登陆操作

标签:window   cli   pass   初始化   highlight   win   files   _id   chrome   

原文地址:http://www.cnblogs.com/gongxr/p/7265981.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!