【Web_UIテスト_Python 3_要素判定とエラー情報抽出】要素の有無/ページエラー情報抽出、インタフェーステストページ情報断言、自動化テストケース


#  
def isElementExitst(self,driver,element):
    '''    
    @param driver:  
    @param element:  
    @return:  
    '''
    self.driver.implicitly_wait(5)
    flag = True
    try:
        driver.find_element_by_xpath(element)
        return flag
    except:
        flag = False
        return flag
    self.driver.implicitly_wait(20)

#  
def get_message(self):
    Basic().wait_time_progress_bar(1, " ")
    basic_xpath = '//div[@class="ant-message-notice-content"]'
    error_xpath = '//div[@class="ant-message-custom-content ant-message-error"]'
    if self.isElementExitst(self.driver, basic_xpath):
        basic_text = self.driver.find_element_by_xpath(basic_xpath).text
        print('\033[0;33m' + f"---- :{basic_text}" + '\033[0m')
        if " " in basic_text:
            return basic_text
        if self.isElementExitst(self.driver, error_xpath):
            error_text = self.driver.find_element_by_xpath(error_xpath).text
            print('\033[0;33m' + f"
---- :{error_text}" + '\033[0m') # input("
---- , ----") return error_text # time.sleep(30) else: print('\033[0;33m' + f"
---- :None" + '\033[0m') return None # Basic().wait_time_progress_bar(1, " ")