Python 对于使用appium的ios自动化,如何以通用方式查找使用文本的元素?

Python 对于使用appium的ios自动化,如何以通用方式查找使用文本的元素?,python,ios,automation,appium,Python,Ios,Automation,Appium,我不熟悉使用appium的ios自动化。我试图在python的appium automation中获得一个基于文本的元素。我当前正在使用以下命令获取文本: uiel=self.driver.find_element_by_xpath('//xguielementtypestatictext[@label=“abc”]')) 假设我想为IOS编写一个api find_element_by_text(string),我必须传递元素和字符串的类型,并根据我应该调用的元素类型,按x_路径查找元素,如图所

我不熟悉使用appium的ios自动化。我试图在python的appium automation中获得一个基于文本的元素。我当前正在使用以下命令获取文本:

uiel=self.driver.find_element_by_xpath('//xguielementtypestatictext[@label=“abc”]'))

假设我想为IOS编写一个api find_element_by_text(string),我必须传递元素和字符串的类型,并根据我应该调用的元素类型,按x_路径查找元素,如图所示:

           if ios_button:
               uiel = self.driver.find_element_by_xpath('//XCUIElementTypeButton[@label="'+ aString +'"]')
           elif is_other:
               uiel = self.driver.find_element_by_xpath('//XCUIElementTypeOther[@label="' + aString + '"]')
           elif is_cell:
               uiel = self.driver.find_element_by_xpath('//XCUIElementTypeCell[@label="' + aString + '"]')
           else:
               uiel = self.driver.find_element_by_xpath('//XCUIElementTypeStaticText[@label="' + aString + '"]' )

有没有一种方法可以在IOS中只使用一行来获取元素,而不必进行上述所有检查?

将元素类型作为与类型关联的实际字符串(“按钮”、“其他”、“单元格”、“静态文本”)发送,然后使用连接创建查找,您已经了解了这一点

uiel = self.driver.find_element_by_xpath('//XCUIElementType' + myElementType + '[@label="'+ aString +'"]')

我没有试运行过这段代码;可能有语法错误,但你应该明白。

这是一个好建议。但我的问题是,每个设备中的元素类型对我来说都是不同的。假设我有一个“元素x”。它的类型在ipod中是XUIElementTypeOther,而在iphone6中是XUIElementTypeStaticText。所以我想知道是否有一种通用的方法来检查,我不清楚为什么元素在同一个平台上会不同,但是你在寻找软件做一些它不知道如何做的事情。您仍然可以使用我建议的想法,但您必须告诉Appium系统的映射,并根据设备类型选择正确的映射。