Esempio n. 1
0
class Base():
    def __init__(self,driver):
        self.driver=driver
        self.log=FrameLog().log()

    def findele(self,*args):
        try:
            print(args)
            self.log.info("通过"+args[0]+"定位,元素是"+args[1])
            return self.driver.find_element(*args)
        except:
            self.log.error("定位元素失败")

    def click(self,args):
        self.findele(args).click()

    def sendkey(self,args,value):
        self.findele(args).send_keys(value)

    def js(self,str):
        self.driver.execute_script(str)

    def url(self):
        return self.driver.current_url

    def back(self):
        self.driver.back()

    def forward(self):
        self.driver.forward()

    def quit(self):
        self.driver.quit()
Esempio n. 2
0
class Base():
    def __init__(self, driver):
        self.driver = driver
        self.log = FrameLog().log()

    def findele(self, *args):
        try:
            print(args)
            self.log.info("通過" + args[0] + "定位,元素是" + args[1])
            # 設定9秒是因為有時候廣告間會有一段緩衝,約 9秒
            return WebDriverWait(self.driver, 9).until(
                EC.presence_of_element_located(
                    (args)))  #self.driver.find_element(*args)
        except:
            self.log.error('locate fails!')

    def Choose(self, time_):  # 用來根據廣告的長短類型來分類廣告
        if time_[0:1] == int:  # 考慮到10min以上的廣告
            time.sleep(31)  # 太長的廣告超過30廟後就跳過
            self.driver.quit()
        elif int(time_[0]) * 60 + int(time_[2:]) > 60:  # 超過60s的廣告則略。這部分自由設定
            time.sleep(31)
            self.driver.quit()
        else:
            secs = int(time_[0]) * 60 + int(time_[2:])  # 若第一則廣告在60s以內則播完
            time.sleep(secs)
Esempio n. 3
0
class Base():
    def __init__(self, driver):
        self.driver = driver
        self.log = FrameLog().log()

    # 单星号参数代表此处接收任意多个非关键字参数
    def findele(self, *args):
        try:
            print(args)
            self.log.info('通过' + args[0] + '定位元素是' + args[1])
            return self.driver.find_element(*args)
        except:
            # 在页面上没有定位到页面元素
            self.log.error('定位元素失败')

    def click(self, *args):
        self.findele(args).click()

    def sendkey(self, *args, value):
        self.findele(args).send_keys(value)

    def js(self, str):
        self.driver.excute_script(str)

    def url(self):
        return self.driver.current_url

    def back(self):
        self.driver.back()

    def forward(self):
        self.driver.forward()

    def quit(self):
        self.driver.quit()
Esempio n. 4
0
class Base():
    def __init__(self, driver):
        self.driver = driver
        self.log = FrameLog().log()

    def findele(self,*args):
        try:
            self.log.info("通過"+args[0]+"定位,元素是"+args[1])
            return WebDriverWait(self.driver, 5).until(EC.presence_of_element_located((args)))
        except:
            self.log.error('locate fails!')
Esempio n. 5
0
class Base():
    def __init__(self, driver):
        self.driver = driver
        self.log = FrameLog().log()

    def findele(self, *args):
        try:
            print(args)
            self.log.info("通過" + args[0] + "定位,元素是" + args[1])
            return self.driver.find_element(*args)
        except:
            self.log.error('locate fails!')
Esempio n. 6
0
class Base():
    def __init__(self, driver):
        self.driver = driver
        self.log = FrameLog().log()

    def findele(self, A, B):
        try:
            self.log.info("通過" + A + "定位,元素是" + B)
            locator = (A, B)
            return WebDriverWait(self.driver, 5).until(
                EC.presence_of_element_located(locator))
        except:
            self.log.error('locate fails!')
Esempio n. 7
0
class Base():
    def __init__(self, driver):
        self.driver = driver
        self.log = FrameLog().log()

    def findele(self, *args):
        try:
            print(args)
            self.log.info("通過" + args[0] + "定位,元素是" + args[1])
            return self.driver.find_element(*args)
        except:
            self.log.error('locate fails!')

    def select_(self, *args, name):
        self.select = Select(self.findele(*args))
        self.select.select_by_visible_text(name)
Esempio n. 8
0
class Base():
    def __init__(self, driver):
        self.driver = driver
        self.log = FrameLog().get_log()

    # 单星号参数代表此处接收任意多个非关键字参数
    def findele(self, *args):
        try:
            print(args)
            self.log.info("通过" + args[0] + "定位,元素是" + args[1])
            return self.driver.find_element(*args)
        except:
            # 在页面上没有定位到元素
            self.log.error("定位元素失败!")

    # 对元素click
    def click(self, args):
        self.findele(args).click()

    # 输入值
    def sendkey(self, args, value):
        self.findele(args).send_keys(value)

    # 调用js方法
    def js(self, str):
        self.driver.execute_script(str)

    def url(self):
        return self.driver.current_url

    # 后退
    def back(self):
        self.driver.back()

    # 前进
    def forward(self):
        self.driver.forward()

    # 退出
    def quit(self):
        self.driver.quit()