Appium the selection / operation element

How Appium is selected, the operation elements of it?

     appium automation ------ select interface elements

     Operating elements ------- ① Click

                            ② input characters

                            ③ drag

                            ④ get various attributes of page elements

     The analysis and processing of data acquired appium

How to view the interface elements of it?

      Use the tools in the tool Androidsdk directory -> bin -> uiautomatorviewer.bat double click to open

Select the page element APP three ways :

      Code selection elements

              And selenium is basically the same

              * The first element find_element_by_xxx qualifying, could not find an exception is thrown

              * A list of qualifying all the elements find_elements_by_xxx, could not find an empty list

              * Look through the entire interface is webDriver tree

              * Look through webelement is a child of that node

      Select the element method

          ① The ID ------ driver.find_element_id ( 'xxxx')

          ② 根据class  name   --------   driver.find_element_by_class_name("android.widget.TextView")

                   The class attribute determines the type of interface elements

                   If we're looking for is some type of interface elements, and this is only one type of interface elements in the current interface

          ③ 根据accessibility  id     ------   driver.find_element_by_accessibility_id('unique name')

                   content-desc attribute is used to describe the action of the element

                   content-desc attribute interface elements if you want to query the current page only to use it

                   However, developers generally do not like to fill it.

          ④ According xpath

                    In appium, we can not use css, css because the web is dedicated. appium support xpath to locate elements.

                    举例:   driver.find_element_by_xpath('//ele/ele2[@attr="a1"]')

                                xpath = "//*[@resource-id='io.manong.developerdaily:id/tab_bar_container']//android.widget.TextView[3]"

                                xpath = "//*[@resource-id='io.manong.developerdaily:id/tab_bar_container']//android.widget.TextView[@text='发现']"

                                eles = driver.find_element_by_xpath(xpath)[2]

                    Note: the subscript indicates xpath starting from 1, but showing in python index is zero-based.

                    Each node corresponds to the relative immaturity of the class attribute, very often can not figure out the correct syntax elements

We encountered when targeting elements pit : EOF frequently reported errors, several solutions

        - Turn off appium server, and then open again uiautomatorviewer.bat

        - Mobile Assistant can not have a computer, and some words are turned off

        - restart the phone, reconnect adb devices

        - delete the test package, re-download, restart uiautomatorviewer

Inspetor positioning:

      Because they can not locate elements with UIAutomator viewer in real-time tool, you can click on the magnifying glass appium server interface, fill in the appropriate name value, and then start session about,

Graphic elements can be achieved with real-time location. Of course Inspetor can also verify xpath expression.

     By Inspactor the Attach to Session can know what equipment.

     How to view the session id can be added to print (driver.session_id) in the code

tap method: and click method is similar to all click interface.

      The difference is: tap method for positioning coordinates; clicking and click method.

      tap method is applicable scene: In less than a selected element, if we can be achieved by positioning coordinates.

        driver.find_element_by_class_name ( '...') # wait screen appears

        driver.tap ([918,413], 4556) # There are two parameters element position and click duration (ms)

 == If the resolution of the phone is different, with the coordinates of positioning is very accurate. You can coordinate the different elements of the corresponding resolution of all written in the configuration file, and then call.

      config.py file write:

         coordinates = {

                 '1080p':{

                       'Home _ +': (548, 1839),

                       'Login page _ the mailbox icon': (147, 1802),

                       'Login page _ E-mail address': (264, 370),

                       'Email password login page _': (264, 570),

                       'Login page _ the login button': (264, 780)

                  },

                  '720p': {

                       'Home _ +': (640, 1250),

                       .......

                  },

                  '2k':{

                       .......

                   }

         }

         cfg_phone_resolution = '1080p'

    Time of the call, such as the pilot package: from appium_code.configs import coordinates, cfg_phone_resolution

     Then when the need to use, such as: coordinate = coordinates [ '1080p']

                                         driver.tap ([coordinate [ 'Home _ +']], 300)

                                         .....

Guess you like

Origin www.cnblogs.com/peipei-Study/p/11989229.html