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

定位元素的封装

时间:2017-09-19 16:16:27      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:password   select   nbsp   _id   tps   and   webdriver   .com   span   

封装定位元素和login函数,在fengzhuang.py中

#coding=utf-8
import time
from selenium import webdriver
#第三版本:封装定位元素
def findID(driver,ID):
return driver.find_element_by_id(ID)
def findLINK(driver,LINK):
return driver.find_element_by_link_text(LINK)
def findCss(driver,css):
return driver.find_element_by_css_selector(css)
def findXpath(driver,xpath):
return driver.find_element_by_xpath(xpath)
def findTagname(driver,tagname):
return driver.find_element_by_tag_name(tagname)
def login(driver,name,pw):
findLINK(driver,u‘登录‘).click()
time.sleep(2)
findID(driver,‘TANGRAM__PSP_10__userName‘).send_keys(name)
findID(driver, ‘TANGRAM__PSP_10__password‘).send_keys(pw)
findID(driver, ‘TANGRAM__PSP_10__submit‘).click()
time.sleep(2)
dirError=findID(driver,‘TANGRAM__PSP_10__error‘).text
driver.close()
assert u‘请您输入‘in dirError


在baidu.py中调用login函数
#coding=utf-8
import time
from selenium import webdriver
from fengzhuang import login
driver=webdriver.Firefox()
driver.maximize_window()
driver.implicitly_wait(30)
driver.get(‘https://www.baidu.com/‘)
login(driver,‘panda‘,‘123456‘)
time.sleep(3)
driver.quit()
 

定位元素的封装

标签:password   select   nbsp   _id   tps   and   webdriver   .com   span   

原文地址:http://www.cnblogs.com/sunny0/p/7552295.html

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