首页 > 代码库 > selenium之封装登陆操作
selenium之封装登陆操作
# 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之封装登陆操作
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。