def assertElementEqule(self, by, locator, value): ''' 检查指定元素字符串与指定元素字符串是否相同 :return: ''' # try: getValue1 = ObjectMap(self.driver).getElement(by, locator).get_attribute('value') getText1 = ObjectMap(self.driver).getElement(by, locator).text getValue2 = ObjectMap(self.driver).getElement(by, value).get_attribute('value') getText2 = ObjectMap(self.driver).getElement(by, value).text if getValue1 == getValue2 and getValue1 != '0' and getValue1 is not None: print(1) assert getValue1 == getValue2 logger.info('%s=%s' % (getValue1, getValue2)) print('%s=%s' % (getValue1, getValue2)) elif getValue1 == getText1 and getValue1 != '0' and getValue1 is not None: print(12) assert getValue1 == getText1 logger.info('%s=%s' % (getValue1, getText1)) print('%s=%s' % (getValue1, getText1)) elif getText1 == getValue2 and getValue2 != '0' and getValue2 is not None: print(13) assert getText1 == getValue2 logger.info('%s=%s' % (getText1, getValue2)) print('%s=%s' % (getText1, getValue2)) elif getText1 == getText2 and getText1 != '' and getText1 is not None: print(14) assert getText1 == getText2 logger.info('%s=%s' % (getText1, getText2)) print('%s=%s' % (getText1, getText2)) else: assert getText1 == getText2 logger.info('%s=%s' % (getText1, getText2)) print('%s=%s' % (getText1, getText2))
def clearAndInput(self, by, locator, value): ''' 清除输入框再输入值 :return: ''' logger.info('清空输入框') print('清空输入框') ObjectMap(self.driver).getElement(by, locator).clear() logger.info('输入框输入%s' % value) print('输入框输入%s' % value) ObjectMap(self.driver).getElement(by, locator).send_keys(value)
def assertElement(self, by, locator, flag): ''' 判断元素是否存在 :return: ''' # flag = True # try: if flag.lower() == 'true': assert ObjectMap(self.driver).getElement(by, locator) else: assert not ObjectMap(self.driver).getElement(by, locator)
def assertElement(self, by, locator): ''' 判断元素是否存在 :return: ''' # flag = True # try: assert ObjectMap(self.driver).getElement(by, locator)
def click(self, by, locator): """ 元素点击 :return: """ # try: logger.info('点击元素:%s' % locator) print('点击元素:%s' % locator) ObjectMap(self.driver).getElement(by, locator).click()
def clear(self, by, locator): """ 清空输入框 :return: """ # try: logger.info('清空输入框') print('清空输入框') ObjectMap(self.driver).getElement(by, locator).clear()
def switchToFrame(self, by, locator): """ 切换到frame页面内 :param by: :param locator: :return: """ # try: self.driver.switch_to.frame(ObjectMap(self.driver).getElement(by, locator))
def uploadFile(self, by, locator, value): ''' 上传单个文件input标签 type="file" :param by: :param locator: :param value: :return: ''' ObjectMap(self.driver).getElement(by, locator).send_keys(value) logger.info('上传文件%s' % value) print('上传文件%s' % value)
def assertLen(self, by, locator, value): ''' 检查指定元素字符串长度 :return: ''' # try: getValue = ObjectMap(self.driver).getElement(by, locator).get_attribute('value') getText = ObjectMap(self.driver).getElement(by, locator).text if len(getText) == int(value): assert len(getText) == int(value) logger.info('%s=%s' % (len(getText), int(value))) print('%s=%s' % (len(getText), int(value))) elif len(getValue) == int(value): assert len(getValue) == int(value) logger.info('%s=%s' % (len(getValue), int(value))) print('%s=%s' % (len(getValue), int(value))) else: assert len(getValue) == int(value) logger.info('%s=%s' % (len(getValue), int(value))) print('%s=%s' % (len(getValue), int(value)))
def assertEqule(self, by, locator, value): ''' 检查指定元素字符串与预期结果是否相同 :return: ''' # try: getValue = ObjectMap(self.driver).getElement(by, locator).get_attribute('value') getText = ObjectMap(self.driver).getElement(by, locator).text if getText == value: assert getText == value logger.info('%s=%s' % (getText, value)) print('%s=%s' % (getText, value)) elif getValue == value: assert getValue == value logger.info('%s=%s' % (getValue, value)) print('%s=%s' % (getValue, value)) else: assert getValue == value logger.info('%s=%s' % (getValue, value)) print('%s=%s' % (getValue, value))
def inputValue(self, by, locator, value): """ 输入框输入值 :param by: :param locator: :param value: :return: """ # try: logger.info('输入框输入%s' % value) print('输入框输入%s' % value) ObjectMap(self.driver).getElement(by, locator).send_keys(value)
def uploadFiles(self, by, locator, value): ''' 上传多个文件,value为文件夹路径, :param by: :param locator: :param value: :return: ''' for root, dirs, files in os.walk(value): for i in files: ObjectMap(self.driver).getElement(by, locator).send_keys(value+'\\'+i) logger.info('上传文件%s' % i) print('上传文件%s' % i)
def Enter(self, by, locator): # 模拟键盘回车 ObjectMap(self.driver).getElement(by, locator).send_keys(Keys.ENTER)
def assertLen(self, by, locator, value): ''' 检查指定元素字符串长度 :return: ''' # try: getValue = ObjectMap(self.driver).getElement( by, locator).get_attribute('value') getText = ObjectMap(self.driver).getElement(by, locator).text if getValue == getText: assert len( ObjectMap(self.driver).getElement( by, locator).get_attribute('value')) == int(value) logger.info('"%s"长度为%s' % (ObjectMap(self.driver).getElement( by, locator).get_attribute('value'), value)) print('"%s"长度为%s' % (ObjectMap(self.driver).getElement( by, locator).get_attribute('value'), value)) elif getValue == '' or getValue is None: assert len(ObjectMap(self.driver).getElement( by, locator).text) == int(value) logger.info( '"%s"长度为%s' % (ObjectMap(self.driver).getElement(by, locator).text, value)) print('"%s"长度为%s' % (ObjectMap(self.driver).getElement(by, locator).text, value)) elif getText == '' or getText is None: assert len( ObjectMap(self.driver).getElement( by, locator).get_attribute('value')) == int(value) logger.info('"%s"长度为%s' % (ObjectMap(self.driver).getElement( by, locator).get_attribute('value'), value)) print('"%s"长度为%s' % (ObjectMap(self.driver).getElement( by, locator).get_attribute('value'), value)) else: assert len( ObjectMap(self.driver).getElement( by, locator).get_attribute('value')) == int(value) logger.info('"%s"长度为%s' % (ObjectMap(self.driver).getElement( by, locator).get_attribute('value'), value)) print('"%s"长度为%s' % (ObjectMap(self.driver).getElement( by, locator).get_attribute('value'), value))
''' # try: element = self.driver.find_element(by, locator) t = self.driver.find_element(by, locator).text ActionChains(self.driver).move_to_element(element).perform() logger.info("鼠标悬浮在%s" %t) print("鼠标悬浮在%s" %t) # except: # logger.exception("未找到元素") # print("未找到元素") if __name__ == '__main__': p = PageAction() p.openBrowser() o = ObjectMap(p.driver) # p.saveScreeShot('登录', '侧四') # p.getUrl('http://172.16.45.5') str = 'p.getUrl("http://172.16.45.5")' eval(str) p.inputValue('name','account','admin') p.inputValue('name','password','admin') p.click('id','loginBtn') p.click('css','#tableBox > div > table > tbody > tr:nth-child(1) > td.tdC3 > span > a') p.click('css','#iframeLeftMune > div.muneList > div:nth-child(2) > ul > a:nth-child(5) > li') p.text_wait_find_element('css', '#meetingDatum > div.table_w.clear.tableWrapComm > div.m-meeting-datum-hd-bg > ul > li:nth-child(2)', '排序') # assert ObjectMap(p.driver).getElement('css', '.f-flex-content.table_n.clear > li:nth-child(2)') # print(o.getElement('css', '.f-flex-content.table_n.clear > li:nth-child(2)').get_attribute('value')) # print(o.getElement('css', '.f-flex-content.table_n.clear > li:nth-child(2)').text) # p.assertEqule('css','.f-flex-content.table_n.clear > li:nth-child(2)','排序') # p.click('css', '.linkColor')