Exemplo n.º 1
0
    def get_verify_code(self, driver, by):
        u"""获取图片验证码"""
        # 验证码图片保存地址
        screenImg = verify_code
        # 浏览器页面截图
        driver.get_screenshot_as_file(screenImg)
        # 定位验证码大小
        location = wd.find_element(driver, by).location
        size = wd.find_element(driver, by).size

        left = location['x']
        top = location['y']
        right = location['x'] + size['width']
        bottom = location['y'] + size['height']

        # 从文件读取截图,截取验证码位置再次保存
        img = Image.open(screenImg).crop((left, top, right, bottom))
        img.convert('L')  # 转换模式:L|RGB
        img = ImageEnhance.Contrast(img)  # 增加对比度
        img = img.enhance(2.0)  # 增加饱和度
        img.save(screenImg)
        # 再次读取验证码
        img = Image.open(screenImg)
        time.sleep(1)
        code = pytesseract.image_to_string(img)
        return code
Exemplo n.º 2
0
    def switch_iframe(self, driver, by, doc=''):
        log.logger.info('{0} - 切换页面表单:{1}'.format(doc, by))
        try:

            wd.get_switch_iframe_element(driver, by)
        except TimeoutException as t:
            log.logger.error('error: found "{}" timeout!'.format((by), t))
        except NoSuchElementException as e:
            log.logger.error('error: no such "{}"'.format((by), e))
        except Exception as e:
            raise e
Exemplo n.º 3
0
 def js_fours_element(self, driver, by, doc=''):
     log.logger.info('{0} - 聚焦元素'.format(doc))
     try:
         element = wd.find_element(driver, by)
         driver.execute_script("arguments[0].scrollIntoView();", element)
     except:
         log.logger.error('{0} - 聚焦元素失败!!!'.format(doc))
Exemplo n.º 4
0
 def move_actionchains_element(self, driver, by, doc=''):
     log.logger.info('{0} - 鼠标悬停操作'.format(doc))
     try:
         element = wd.find_element(driver, by)
         ActionChains(self.driver).move_to_element(element).perform()
     except:
         log.logger.error('{0} - 鼠标悬停操作 失败!!!'.format(doc))
         raise
Exemplo n.º 5
0
 def get_element_attribute(self, driver, by, name, doc=''):
     log.logger.info('{0},获取页面元素属性:{1}'.format(doc, by))
     try:
         element = wd.get_attribute_element(driver, by, name)
         return element
     except:
         log.logger.error('{0},页面元素的属性获取 失败!!!'.format(doc))
         raise
Exemplo n.º 6
0
 def get_element_text(self, driver, by, doc=''):
     log.logger.info('{0} - 获取页面元素:{1}'.format(doc, by))
     try:
         element = wd.find_element(driver, by).text
         return element
     except:
         log.logger.error('{0},页面元素的文本获取失败!!!'.format(doc))
         raise
Exemplo n.º 7
0
 def input_element(self, driver, by, value, doc=''):
     log.logger.info('{0} - 页面元素:{1} 输入值 {2}'.format(doc, by, value))
     try:
         element = wd.get_clickable_element(driver, by)
         element.send_keys(value)
     except:
         log.logger.error('{0} - 页面元素输入失败!!!'.format(doc))
         raise
Exemplo n.º 8
0
 def get_element(self, driver, by, doc=''):
     log.logger.debug(by)
     log.logger.info('{0} - 查找页面元素:{1}'.format(doc, by))
     try:
         self.wait_eleVisible(by, doc)
         return wd.find_element(driver, by)
     except:
         log.logger.error('{0},查找页面元素:{1} 失败!!!'.format(doc, by))
         raise (NoSuchElementException, TimeoutException)
Exemplo n.º 9
0
 def click_element(self, driver, by, doc=''):
     #self.wait_eleVisible(way, doc)
     log.logger.info('{0} - 点击页面元素:{1}'.format(doc, by))
     try:
         element = wd.get_clickable_element(driver, by)
         element.click()
     except:
         log.logger.error('点击页面元素:{0},失败!!!'.format(by))
         raise
Exemplo n.º 10
0
 def alter_action(self, driver, doc=''):
     log.logger.info('{0} - 处理页面的alter'.format(doc))
     try:
         element = wd.get_alert_is_present(driver)
         content = element.text
         log.logger.info('{0} - alter的内容:{1}'.format(doc, content))
         # 接受alter
         element.accept()
         return content
     except:
         log.logger.error('{0} - 页面元素的alter获取 失败!!!'.format(doc))
         raise
Exemplo n.º 11
0
 def select_by_text(self, driver, by, text):
     u"""通过text定位元素"""
     element = wd.find_element(driver, by)
     Select(element).select_by_visible_text(text)
Exemplo n.º 12
0
 def select_by_value(self, driver, by, value):
     u"""通过value定位元素"""
     element = wd.find_element(driver, by)
     Select(element).select_by_value(value)
Exemplo n.º 13
0
 def slect_by_index(self, driver, by, index):
     u"""通过多有index,0开始,定位元素"""
     element = wd.find_element(driver, by)
     Select(element).select_by_index(index)