Both are returned as bool values, which means thatif xxx:
.is_selected() : Used to check whether the radio or multi-selection box is selected
radio: radio button (only one can be selected)
checkbox: checkbox (multiple choices are possible)
.is_enable(): Determine whether an element is clickable
. is_display(): Determine whether an element is displayed,
but sometimes none of the above three can be determined:
the requirement is to enter this page, and it is necessary to intelligently detect the status of the video button and keep the button closed
as follows, the button On or off, the values of the three fields have not changed, so the above method cannot be used directly
But when the button is turned on, the element 'beauty' will appear,
so you can intelligently detect the button status by judging whether the 'beauty' element exists
# 如果"美颜"元素存在,证明视频按钮打开,就点击按钮关闭,否则按钮已经关闭,继续往下走
def off_videobtn(dr):
if dr.find_elements('-android uiautomator', 'new UiSelector().text("美颜")'):
dr.find_element('id','com.tencent.wemeet.app:id/gi').click()
else:
pass
At the beginning, a find element was used here. When the video button is turned on, it can run through, but when it is turned off, an error will be reported if the beauty element cannot be found.
Later, after checking, you can change it to elements , because if element cannot find the element, it will directly report an error and will not go down, but if elements are not found, it will return an empty list, and you can continue to go down
Summary:
Appium's method of judging elements:
- .is_selected()
- .is_display()
- .is_enable()
- See if there are related elements appear after the button is opened or closed and use elements to find and judge