1炊豪、屏幕滑動方法
def swipe_Down(self):
window_size = self.driver.get_window_size()
width = window_size.get("width")
height = window_size.get("height")
self.driver.swipe(width/2,height/4,width/2,height*3/4,500)
def swipe_Up(self):
window_size = self.driver.get_window_size()
width = window_size.get("width")
height = window_size.get("height")
self.driver.swipe(width/2,height*3/4,width/2,height/4,500)
def swipe_Left(self):
window_size = self.driver.get_window_size()
width = window_size.get("width")
height = window_size.get("height")
self.driver.swipe(width/4,height/2,width*3/4,height/2,500)
def swipe_Rigth(self):
window_size = self.driver.get_window_size()
width = window_size.get("width")
height = window_size.get("height")
self.driver.swipe(width*4/5,height/2,width/5,height/2,500)
2鳍徽、封裝查找元素及自動等待方法
def find_elements(self,loc):
'''封裝一組元素定位方法'''
try:
if len(self.driver.find_elements(*loc)):
return self.driver.find_elements(*loc)
except Exception as e:
print(u"%s 頁面中未能找到 %s 元素" %(self,loc))
return False
def find_element(self,loc):
'''封裝單個(gè)元素定位方法'''
try:
WebDriverWait(self.driver,15.).until(lambdadriver:driver.find_element(*loc).is_displayed())
return self.driver.find_element(*loc)
except Exception as e:
print(u"%s 頁面中未能找到 %s 元素" %(self,loc))
return False
3上沐、保存圖片
def take_Shot(self,name):
day = time.strftime('%Y-%m-%d', time.localtime(time.time()))
fp = "..\\Result\\" + day
tm = time.strftime('%Y-%m-%d-%H_%M_%S', time.localtime(time.time()))
type = '.png'
filename = ''
if os.path.exists(fp):
filename = fp+"\\" + tm +'_'+ name + type
else:
os.makedirs(fp)
filename = fp+"\\" + tm +'_'+ name + type
self.driver.save_screenshot(filename)
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者