When used to find the method of clicking on the element name, ID, classname, etc. can not be used, we will take the coordinates of the click to achieve the operation, there is also a problem, when the phone resolution, screen size is inconsistent, coordinate positioning will be different, so will use relative coordinates to achieve the click.
1, appium/webdriver the bottom of the written example of the following, the detailed method of the introduction of self-view of the bottom, here does not give a description.
: Usage: Driver.tap ([(+)], ( )
2, the common wording of the problems that arise:
How to view coordinates in your phone: Turn on the phone's pointer position (settings-about mobile-developer options-pointer position), click on the top of an element phone to display the coordinates.
Error one: Directly given the coordinate values you want to click: X and Y
Self.device.tap (465) #如某个元素的坐标x =250,y=465, the direct given coordinates are as follows
Error writing two, unclear value how to give, will write X, Y value 2 times, refer to the bottom method, as follows:
Self.device.tap ([(465), (+,465)],
Perform the above operation will appear error : attributeerror:driver_elements instance has no attribute ' tap '
3, the correct click Coordinate value acquisition method:
If you open Uiautomatorview, point to the bounds value in the lower-right corner of the element you want to get, it is the coordinate value of this element. As follows:
The wording is:
Self.device.tap ([(711,761), (909,959)],+)
4, click the coordinate method package
def Touch_tap (self,x,y,duration= -): #点击坐标, x1,x2,y1,y2,duration " method explain: Click coordinates parameter explain:" X, y "coordinate value," duration ": The value given determines the speed of the click Usage:devic E.touch_coordinate (277,431) #277.431 to click the X and y values of an elementScreen_width = Self.driver.get_window_size () ['width'] #获取当前屏幕的宽screen_height= Self.driver.get_window_size () ['Height'] #获取当前屏幕的高a=(float(x)/screen_width) *screen_width X1=int(a) b= (float(y)/screen_height) *screen_height Y1=int(b) Self.driver.tap ([(X1,y1), (x1,y1)],duration)
Android+appium +python Click on the coordinates of the tap method package