There are two solutions available!
1. android 6.0+ is able to directly use the uiautomator positioning element Click! This does not elaborate , the positioning of a variety of ways ... This wait time everybody oneself decide holding can!
#安卓6.0+ Click Mode
Driver.find_element_by_android_uiautomator ('new Uiselector (). Textcontains ("Allow")' )
But generally, most of the pop-up window is a lot of good---Use the display wait: After the app is launched, in three seconds no 0.5 seconds to look for an element, if there is a click, does not exist the error direct pass
try : While true:element = ( " xpath ", " //*[contains (@text, ' Allow ')] ) ac = webdriverwait (Driver, 3, 0.5). Until (lambda< /span> Driver:driver.find_element_by_xpath ( ' // *[contains (@text, "allow")] " except : pass
2. There is also a way to locate the following, pro-test support for the high version, but I did not personally try to support the lower version of the mobile phone permissions pop-up window-----Because I'm not using these two---personal method compared simple rude + direct
But, here is recommended to make a low version of the mobile phone to try, I did not test because the condition is not allowed to find the lower version of the mobile phone .... Hope to have a friend test after the message a wave, let me have a bottom ....
Try : while True: = ("XPath""//*[contains (@text, ' Allow ')]") = webdriverwait (driver, 1, 0.5). Until (ec.presence_of_element_located (element)) Ac.click () except : Pass
-
- then manually install the app once for each phone , and use Notepad to get the other stuff to write down the device name
-
- Open The app and get ready to Uiautomatorview (the location element in the SDK directory). ), as shown in remember this coordinate, such as:
admin_lists={' 2905BDB6 ': [(360,1149)], ' xxxx ': [()]}, If you do not locate the "allow" the coordinates, you can manually point to allow, according to the fixed, you will find the screen at the top of a coordinate dx:--/dy: --and make note of the same coordinates!
admin_list={'2905BDB6': [(360,1149)],'xxxx': [()]} forAinchadmin_list:devicelist=''. Join (Os.popen ('ADB devices'). ReadLines ()) Device=re.findall (R"(.+?) \ t", Devicelist) [0]Print(Device)ifa==Device:driver.tap (Admin_list[a])
The principle is to first put our test machine pop-up permission to record the coordinates, the first time when the installation started to query the device name and then take the coordinates, and then click---This method is also suitable for multiple devices
The method is a bit of fishing, but practical ---the other here do not want to go to fit the screen, this does not exist, according to my understanding of different mobile phone pop-up style may not be the same.
if only one pops up -just use the method above, but if there are multiple permissions on the popup window:
Add a method can be ---have a number of words, this will have to according to their own app debugging ... But very similar.
As shown below:
admin_list={'2905BDB6': [(360,1149)],'xxxx': [()]} forAinchadmin_list:devicelist=''. Join (Os.popen ('ADB devices'). ReadLines ()) Device=re.findall (R"(.+?) \ t", Devicelist) [0]Print(Device)ifa==Device: forIinchRange (5): Driver.tap (Admin_list[a]) time.sleep (3)
there should be a lot of nasty methods --You can study it yourself, as long as it can be achieved, I personally do not have too much of a performance--(unexpected words)
This chapter has a certain python syntax:
Loop, Regular,OS, range, ReadLines, dict value----If this does not know very well-suggest to see the Python3 course of Liu Xuefeng---Direct Baidu Liaoche can be