from init_driver.Init_driver import init_driver driver = init_driver() try: # 模拟输入文本框 # 点击搜索按钮 driver.find_element_by_id("com.android.settings:id/search").click() for i in ("wi", "Le", "花"): input_ele = driver.find_element_by_class_name("android.widget.EditText") # 清空文本 input_ele.clear() # 输入文字 input_ele.send_keys(i) # 下拉 xiala_data = driver.find_element_by_class_name("android.widget.TextView").text if xiala_data: print(True) else: print(False) # 点击取消,返回主页 driver.find_element_by_class_name("android.widget.ImageButton").click() # 获取元素的属性值 # value = 'name',返回content - desc / text属性值 data1 = driver.find_element_by_id("com.android.settings:id/search").get_attribute("name") # value = 'text',返回text的属性值 data2 = driver.find_element_by_id("com.android.settings:id/search").get_attribute("text") # value = 'className',返回class属性值,只有,API = > 18才能支持 data3 = driver.find_element_by_id("com.android.settings:id/search").get_attribute("className") # value = 'resourceId',返回resource - id属性值,只有API = > 18才能支持 data4 = driver.find_element_by_id("com.android.settings:id/search").get_attribute("resourceId") # 获取元素在屏幕上的位置 get_loc = driver.find_element_by_id("com.android.settings:id/search").location print(get_loc) # 获取包名和启动名 print("包名:", driver.current_package) print("启动名:", driver.current_activity) except Exception as e: print(e) finally: driver.quit()