base--PageBase
Posted wenjing2019
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了base--PageBase相关的知识,希望对你有一定的参考价值。
import time,os
from selenium import webdriver
from cwp.util.logger import logger
logger = logger(logger=‘base_page‘).getlog()
class PageBase(object):
def __init__(self,driver = None):
if driver is None:
os.system(‘taskkill / im chromedriver.exe /f‘)
self.driver = webdriver.Chrome()
else:
self.driver = driver
def get_element(self,*locator):
logger.info(‘查找元素 %s‘%str(locator))
return self.driver.find_element(*locator)
def wait_element(self,*locator):
ele = None
count = 0
while ele is None:
count = count + 1
try:
ele = self.driver.find_element(*locator)
except:
pass
flag = ele is not None
logger.info("查找元素第%d次 %s %s" %(count,flag,str(locator)))
time.sleep(0.1)
if count > 99:
logger.info("没有找到元素 %s " %str(locator))
break
return ele
以上是关于base--PageBase的主要内容,如果未能解决你的问题,请参考以下文章