appium --- simulate a click event

  In doing automated process will encounter some unable to locate the place, or how unsuccessful places are located through the elements, we can use this time to nirvana, by positioning coordinates. Specifically how does it work? 

swipe click event

Quiet written an article on the front page swipe the slide app, swipe in fact, can also simulate a click event, as long as we put back the response time is reduced, then the coordinates become the same coordinates. Details swipe usage can refer appium --- App page slide

View through the tool to the login / register button coordinates [390,831] [522,873], probably considered it coordinates [470,850]

 

 Man of few words said, directly on the code, simulate clicks (registration / login) button by swipe

# Coding: UTF-. 8 
from appium Import the webdriver
 Import Time 
desired_caps = {
                  ' PlatformName ' : ' the Android ' ,   # test version 
                 ' deviceName ' : ' Emulator-5554 ' ,    # device name 
                 ' platformVersion ' : ' 5.1.1 ' , # system version 
                " appPackage " : " com.taobao.taobao ",    # App package name 
                " appActivity " : " com.taobao.tao.welcome.Welcome " ,    # start the Activity Launch 
                " NoReset " : True,   # no clear data 
                        } 
Driver = webdriver.Remote ( ' of http://127.0.0.1 : 4723 / WD / Hub ' , desired_caps)
 # Taobao slow to load, add a delay. 
the time.sleep (16 ) 
X1 = int (470 ) 
Y1 = int (850 ) 
driver.swipe (X1, Y1, X1, Y1, 500)

Use a variety of methods, but the python how it would do this to us? Of course there are better ways than this

tap

tap method represents a click event, by clicking Coordinates, generally used when the element is difficult to locate the

Source

DEF TAP (Self, the Positions, DURATION = None):
         "" " Taps ON AN Particular Place with up to Five Fingers, Holding for A Certain Time 
      # with fingers tapping a particular place, to maintain a certain time 
        : Args: 
         - the Positions - AN array of tuples Representing at the x / y coordinates of 
        # represents an array of tuples x / y coordinates 
         at the Fingers to TAP the length CAN BE up to Five.. 
         - dURATION - (optional) length of Time to TAP, in MS 
     # sustained time in milliseconds 
        : the Usage: 
            driver.tap ([(100, 20 is), (100, 60), (100, 100)], 500) 
        "" "

Here we can directly be positioned directly on the right side by coordinate bonds properties, we do not calculate one

# Coding: UTF-. 8 
from appium Import the webdriver
 Import Time 
desired_caps = {
                  ' PlatformName ' : ' the Android ' ,   # test version 
                 ' deviceName ' : ' Emulator-5554 ' ,    # device name 
                 ' platformVersion ' : ' 5.1.1 ' , # system version 
                " appPackage " : " com.taobao.taobao ",    # App package name 
                " appActivity " : " com.taobao.tao.welcome.Welcome " ,    # start the Activity Launch 
                " NoReset " : True,   # no clear data 
                        } 
Driver = webdriver.Remote ( ' of http://127.0.0.1 : 4723 / WD / Hub ' , desired_caps) 
the time.sleep ( 16 )
 # by clicking tap analog 
driver.tap ([(390,831), ( 522,873)], 500)

 

Note: Replace the phone to run the script, we must replace the coordinates, coordinates of each mobile phone may be different.

 

In fact, there are many methods, here they would not be introduced one by one, continuously updated in ~~~

Guess you like

Origin www.cnblogs.com/qican/p/11612644.html