How to use get_element_location method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

PageFunction_XML.py

Source:PageFunction_XML.py Github

copy

Full Screen

...20 self.function_name = function_name21 self.element_location = element_location22 def get_function_name(self):23 return self.function_name24 def get_element_location(self):25 return self.element_location26def ReadXMlData(xmlPath, parent):27 '''读取配置文件中的信息,并返回每个项为一个(name,element_location)的列表'''28 dom = xmlParser.parse(xmlPath)29 db = dom.documentElement30 data_list = []31 itemlist = db.getElementsByTagName(parent)32 for item in itemlist:33 it = ElementClass(item.getAttribute('Function_name'), item.getAttribute('Element_location'))34 data_list.append(it)35 return data_list36class MakeFunction(Base.Page):37 '''创建元素操作方法'''38 def make_function_click_by_xpath(self, element_location):39 def function_click_by_xpath():40 self.find_element(By.XPATH, element_location).click()41 return function_click_by_xpath42 def make_function_click_by_class_name(self, element_location):43 def function_click_by_class_name():44 self.find_element(By.CLASS_NAME, element_location).click()45 return function_click_by_class_name46 def make_function_send_keys(self,element_location):47 def function_send_keys(message):48 self.find_element(By.XPATH, element_location).send_keys(message)49 return function_send_keys50 def make_function_time_widget1(self,element_location):51 def function_time_widget(id_name, message):52 js = "document.getElementById('" + id_name + "').removeAttribute('readonly');"53 self.driver.execute_script(js)54 self.find_element(By.XPATH, element_location).send_keys(message)55 self.find_element(By.XPATH, element_location).click()56 return function_time_widget57 def make_function_time_widget2(self,element_location):58 def function_time_widget(id_name, message):59 js = "document.getElementById('" + id_name + "').removeAttribute('readonly');"60 self.driver.execute_script(js)61 self.find_element(By.XPATH, element_location).send_keys(message)62 return function_time_widget63 def make_function_hint(self, element_location):64 def function_hint():65 return self.find_element(By.XPATH, element_location).text 66 return function_hint67class FunctionFactory():68 '''功能工厂'''69 def __init__(self, driver, xmlpath):70 self.FunctionMap = {}71 self.driver = driver72 self.InitClickByXpath(xmlpath,"FUNCTION_CLICK_BY_XPATH")73 self.InitClickByClassName(xmlpath, "FUNCTION_CLICK_BY_CLASS_NAME")74 self.InitSendMessage(xmlpath, "FUNCTION_SEND")75 self.InitTimeWidget1(xmlpath, "FUNCTION_TIME_WDIGET1")76 self.InitTimeWidget2(xmlpath, "FUNCTION_TIME_WDIGET2")77 self.InitHint(xmlpath, "FUNCTION_HINT")78 def InitClickByXpath(self, xmlpath, Parent):79 #初始化点击事件,并保存在FuncMap中80 listclickbyxpath = ReadXMlData(xmlpath, Parent)81 for list1 in listclickbyxpath:82 self.FunctionMap[list1.get_function_name()] = MakeFunction(self.driver).make_function_click_by_xpath(list1.get_element_location())83 def InitClickByClassName(self, xmlpath, Parent):84 #初始化点击事件,并保存在FuncMap中85 listclickbyclassname = ReadXMlData(xmlpath, Parent)86 for list1 in listclickbyclassname:87 self.FunctionMap[list1.get_function_name()] = MakeFunction(self.driver).make_function_click_by_class_name(list1.get_element_location())88 def InitSendMessage(self, xmlpath, Parent):89 #初始化信息输入事件,并保存在FuncMap中90 listsSend = ReadXMlData(xmlpath, Parent)91 for list1 in listsSend:92 self.FunctionMap[list1.get_function_name()] = MakeFunction(self.driver).make_function_send_keys(list1.get_element_location())93 def InitTimeWidget1(self, xmlpath, Parent):94 #初始化时间控件事件,并保存在FuncMap中95 listTimeWidget1 = ReadXMlData(xmlpath, Parent)96 for list1 in listTimeWidget1:97 self.FunctionMap[list1.get_function_name()] = MakeFunction(self.driver).make_function_time_widget1(list1.get_element_location())98 def InitTimeWidget2(self, xmlpath, Parent):99 #初始化时间控件事件,并保存在FuncMap中100 listTimeWidget2 = ReadXMlData(xmlpath, Parent)101 for list1 in listTimeWidget2:102 self.FunctionMap[list1.get_function_name()] = MakeFunction(self.driver).make_function_time_widget2(list1.get_element_location())103 def InitHint(self, xmlpath, Parent):104 #初始化元素验证事件,并保存在FuncMap中105 listhint = ReadXMlData(xmlpath, Parent)106 for list1 in listhint:107 self.FunctionMap[list1.get_function_name()] = MakeFunction(self.driver).make_function_hint(list1.get_element_location())108 def RunClick(self, funcname):109 '''运行点击事件'''110 element = self.FunctionMap.get(funcname)111 element()112 def RunSendKeys(self, funcname, message):113 '''运行信息输入事件'''114 element = self.FunctionMap.get(funcname)115 element(message)116 def RunTimeWidget(self, funcname, id_name, message):117 '''运行时间控件事件'''118 element = self.FunctionMap.get(funcname)119 element(id_name, message)120 def RunHint(self, funcname):121 '''运行元素验证事件'''...

Full Screen

Full Screen

operate_yaml.py

Source:operate_yaml.py Github

copy

Full Screen

...21 if self.data.get_find_locator(i) == 'normal':22 """调用action类中的方法实现元素操作"""23 if self.data.get_return(i) == "single":24 if self.data.get_operate(i) == "send_keys":25 el = self.action.find_element(self.data.get_type(i), self.data.get_element_location(i))26 content = self.data.get_content(i)27 else:28 el = self.action.find_element(self.data.get_type(i), self.data.get_element_location(i))29 elif self.data.get_return(i) == "more":30 el = self.action.find_elements(self.data.get_type(i), self.data.get_element_location(i))31 elif self.data.get_find_locator(i) == 'android_uiautomator':32 if self.data.get_return(i) == "single":33 if self.data.get_operate(i) == "send_keys":34 el = self.action.find_byUiautormator(self.data.get_type(i), \35 self.data.get_element_location(i))36 content = self.data.get_content(i)37 else:38 el = self.action.find_byUiautormator(self.data.get_type(i), \39 self.data.get_element_location(i))40 elif self.data.get_return(i) == "more":41 el = self.action.find_elements_byUiautormator(self.data.get_type(i), \42 self.data.get_element_location(i))43 # else:44 # print("输入的元素描述与获取到的数据不一致")45 return el, content46 else:47 return "yaml文件内数据为空!"48# if __name__ == '__main__':49# data = operate_yaml(file_path).operate_yaml("请输入姓名")50# print(type(data))...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run robotframework-appiumlibrary automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful