元素的常用方法
element.click()
element.send_key("")
element.set_value("")
设置元素的值element.clear()
清除element.is_displayed()
是否可见element.is_enabled()
是否可用element.is_selected()
是否被选中get_attribute(name)
获取属性值
元素的常用属性
element.text
获取元素文本element.location
获取元素坐标:{‘y’:19,‘x’:498}element.size
获取元素尺寸(高和宽):{‘width’:500,‘height’:22}
案例
from time import sleep
from appium import webdriver
class TestDW:
def setup(self):
desired_caps = {
"platformName": "Android",
"deviceName": "127.0.0.1:7555",
"platformVersion": "6.0",
"noReset": "true",
"dontStopAppOnReset": "true",
"skipDeviceInitialization": "true",
"unicodeKeyBoard": "true",
"resetKeyBoard": "true"
}
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
self.driver.implicitly_wait(10)
def teardown(self):
self.driver.back()
def test_atrr(self):
"""
1.打开雪球首页
2.定位首页搜索框
3.判断搜索框是否可用,并打印搜索框name属性值
4.打印搜索框左上角坐标和它的宽高
5.向搜索框输入alibaba
6.判断【阿里巴巴】是否可见
7.如果可见,打印“搜索成功”,如果不可见,打印“搜索失败”
"""
search = self.driver.find_element_by_id("com.xueqiu.android:id/tv_search")
search_enabled = search.is_enabled()
print(search.text)
print(search.location)
print(search.size)
if search_enabled == True:
search.click()
self.driver.find_element_by_id("com.xueqiu.android:id/search_input_text").send_keys("alibaba")
alibaba_element = self.driver.find_element_by_xpath("//*[@resource-id='com.xueqiu.android:id/name' and @text='阿里巴巴']")
element_display = alibaba_element.get_attribute("displayed")
if element_display == "true":
print("搜索成功")
else:
print("搜素失败")