读懂appium原理,看这篇就够了

读懂appium原理,看这篇就够了,第1张

#重写元素定位的方法

class Action(object):

#初始化

def __init__(self, se_driver):

selfdriver = se_driver

#通过resource-i定位

def findId(self, id):

try:

f = selfdriverfind_element_by_id(id)

return f

except Exception as e:

print("未找到%s"%(id))

#通过class定位

def findClassName(self, name):

try:

f = selfdriverfind_element_by_class_name(name)

return f

except Exception as e:

print("未找到%s"%(name))

#通过text定位

def findAU(self, name):

try:

f = selfdriverfind_element_by_android_uiautomator('text(\"' + name +'\")')

return f

except Exception as e:

print("未找到%s"%(name))

#通过xpath定位

def findXpath(self, xpath):

try:

f = selfdriverfind_element_by_xpath(xpath)

return f

except Exception as e:

print("未找到%s"%(xpath))

#通过content-desc

def findAI(self, content_desc):

try:

f = selfdriverfind_element_by_access

appium android获取元素方式:

1元素标签(tagname) 通过UI的控件类型ListtextFieldsList=driverfindElements(BytagName( textfield ));

元素的位置(xpath) 具有一定约束的路径抽象标示, 基于XPath方式;

元素的值(name) driverfindElement(Byname( Save ))click();通过元素的文本, 标签, 或者id标示;

元素的IDdriverfindElement(Byid(comexampleandroidcontactmanager:id/contactNameEditText ))getText();

如果是这种情况,就考虑其他的定位方法了,肯定有一种能够解决的。

有这几种方法,也可以用:

一、

如果xpath一样,id不一样的话,可以通过找id(viewer当中的resource-id),

selfdriverfind_element_by_id("comchanjetcspcustomer:id/workrecord_add_content")send_keys(contextfield)

二、

如果一定要用xpath,看看viewer当中@index是不是有一个是0,有一个是1,一般来说不会重;如果真的重了,通过text可者其他的不一致的项,再试试

selfdriverfind_element_by_xpath("//androidwidgetTextView[contains(@text,'报价')]")

除了这些,还有以下的找元素的方式,换一换,总有一个能行的

selfdriverfind_element_by_class_name('androidwidgetImageView')click()

selfdriverfind_element_by_name("新增工作记录")click()

以上就是关于读懂appium原理,看这篇就够了全部的内容,包括:读懂appium原理,看这篇就够了、Appium《元素定位和UiAutomator表达式》、python+appium如何获取元素内容的颜色等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9760834.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-01
下一篇2023-05-01

发表评论

登录后才能评论

评论列表(0条)

    保存