Appium_Python_Apiドキュメント

138445 ワード

Appium Python API中国語版By-HZJ
Appium_Python_Apiドキュメント
1.contexts contexts(self):
    Returns the contexts within the current session.
    H5     

    :Usage:
        driver.contexts
   driver.contexts

2. current_context current_context(self):
    Returns the current context of the current session.
                
    :Usage:
        driver.current_context
  driver. current_context

3. context context(self):
    Returns the current context of the current session.
    
    :Usage:
        driver.context
  driver. Context

4. find_element_by_ios_uiautomation find_element_by_ios_uiautomation(self, uia_string):
Finds an element by uiautomation in iOS.
      iOS uiautomation    
    :Args:
     - uia_string - The element name in the iOS UIAutomation library

    :Usage:
        driver.find_element_by_ios_uiautomation('.elements()[1].cells()[2]')
  dr. find_element_by_ios_uiautomation(elements)

5. find_element_by_accessibility_id find_element_by_accessibility_id(self, id):
Finds an element by accessibility id.
      accessibility id    
    :Args:
     - id - a string corresponding to a recursive element search using the
     Id/Name that the native Accessibility options utilize

    :Usage:
        driver.find_element_by_accessibility_id()
  driver.find_element_by_accessibility_id(id)

6.scroll scroll(self, origin_el, destination_el):
Scrolls from one element to another
       origin_el     destination_el
    :Args:
     - originalEl - the element from which to being scrolling
     - destinationEl - the element to scroll to

    :Usage:
        driver.scroll(el1, el2)
   driver.scroll(el1,el2)


7. drag_and_drop drag_and_drop(self, origin_el, destination_el):
Drag the origin element to the destination element
       origin_el      destination_el
    :Args:
     - originEl - the element to drag
     - destinationEl - the element to drag to
   driver.drag_and_drop(el1,el2)

8.tap tap(self, positions, duration=None):
Taps on an particular place with up to five fingers, holding for a certain time
      (      ),         (  )

    :Args:
     - positions - an array of tuples representing the x/y coordinates of
     the fingers to tap. Length can be up to five.
     - duration - (optional) length of time to tap, in ms

    :Usage:
        driver.tap([(100, 20), (100, 60), (100, 100)], 500)
   driver.tap([(x,y),(x1,y1)],500)

9. swipe swipe(self, start_x, start_y, end_x, end_y, duration=None):
Swipe from one point to another point, for an optional duration.
     A    B    :Args:
     - start_x - x-coordinate at which to start
     - start_y - y-coordinate at which to start
     - end_x - x-coordinate at which to stop
     - end_y - y-coordinate at which to stop
     - duration - (optional) time to take the swipe, in ms.

    :Usage:
        driver.swipe(100, 100, 100, 400)
   driver.swipe(x1,y1,x2,y2,500)


10.flick flick(self, start_x, start_y, end_x, end_y):
Flick from one point to another point.
      A       B 
    :Args:
     - start_x - x-coordinate at which to start
     - start_y - y-coordinate at which to start
     - end_x - x-coordinate at which to stop
     - end_y - y-coordinate at which to stop

    :Usage:
        driver.flick(100, 100, 100, 400)


使用driver.flick(x1,y1,x2,y2) 11.pinch pinch(self, element=None, percent=200, steps=50):
Pinch on an element a certain amount
               (    )
    :Args:
     - element - the element to pinch
     - percent - (optional) amount to pinch. Defaults to 200%
     - steps - (optional) number of steps in the pinch action

    :Usage:
        driver.pinch(element)

使用driver.pinch(element) 12.zoom zoom(self, element=None, percent=200, steps=50):
Zooms in on an element a certain amount
              
    :Args:
     - element - the element to zoom
     - percent - (optional) amount to zoom. Defaults to 200%
     - steps - (optional) number of steps in the zoom action

    :Usage:
        driver.zoom(element)

使用driver.zoom(element) 13.reset reset(self):
Resets the current application on the device.
    (        )
   driver.reset()

14. hide_keyboard hide_keyboard(self, key_name=None, key=None, strategy=None):
Hides the software keyboard on the device. In iOS, use `key_name` to press a particular key, or `strategy`. In Android, no parameters are used.
        ,iOS  key_name

    :Args:
     - key_name - key to press
     - strategy - strategy for closing the keyboard (e.g., `tapOutside`)
driver.hide_keyboard()

15. keyevent keyevent(self, keycode, metastate=None):
Sends a keycode to the device. Android only. Possible keycodes can be found in http://developer.android.com/reference/android/view/KeyEvent.html.
         (    ),           
    :Args:
     - keycode - the keycode to be sent to the device
     - metastate - meta information about the keycode being sent
   dr.keyevent(4)

16. press_keycode press_keycode(self, keycode, metastate=None):
Sends a keycode to the device. Android only. Possible keycodes can be found in http://developer.android.com/reference/android/view/KeyEvent.html.
         (    ),           

    :Args:
     - keycode - the keycode to be sent to the device
     - metastate - meta information about the keycode being sent
   driver.press_ keycode(4)

dr.keyevent(‘4’)とdriver.press_ keycode(‘4’)の機能実装と同様に、いずれもリターンキー17が押す.long_press_keycode long_press_keycode(self, keycode, metastate=None):
Sends a long press of keycode to the device. Android only. Possible keycodes can be
    found in http://developer.android.com/reference/android/view/KeyEvent.html.
              (    )
    :Args:
     - keycode - the keycode to be sent to the device
     - metastate - meta information about the keycode being sent
    driver.long_press_keycode(4)

18.current_activity current_activity(self):
Retrieves the current activity on the device.
     activity
   print(driver.current_activity())

19. wait_activity wait_activity(self, activity, timeout, interval=1):
Wait for an activity: block until target activity presents or time out.
    This is an Android-only method.
         activityinterval     1 
            activity
   True   False
    :Agrs:
     - activity - target activity
     - timeout - max wait time, in seconds
     - interval - sleep interval between retries, in seconds
  driver.wait_activity(.activity.xxx,5,2)

20. background_app background_app(self, seconds):
Puts the application in the background on the device for a certain duration.
        app   
    :Args:
     - seconds - the duration for the application to remain in the background
   driver.background_app(5)      5     

21.is_app_installed is_app_installed(self, bundle_id):
Checks whether the application specified by `bundle_id` is installed on the device.
      app     
   True or False
    :Args:
     - bundle_id - the id of the application to query
   driver.is_app_installed(com.xxxx)

22.install_app install_app(self, app_path):
Install the application found at `app_path` on the device.
      app,app_path      
    :Args:
     - app_path - the local or remote path to the application to install
   driver.install_app(app_path)

23.remove_app remove_app(self, app_id):
Remove the specified application from the device.
      app
    :Args:
     - app_id - the application id to be removed
   driver.remove_app(“com.xxx.”)


24.launch_app launch_app(self):
Start on the device the application specified in the desired capabilities.
  app
   driver.launch_app()

25.close_app close_app(self):
Stop the running application, specified in the desired capabilities, on the device.
  app
   driver.close_app()
     app       

26. start_activity start_activity(self, app_package, app_activity, **opts):
Opens an arbitrary activity during a test. If the activity belongs to
    another application, that application is started and the activity is opened.

    This is an Android-only method.
                。             ,              。
         
    :Args:
    - app_package - The package containing the activity to start.
    - app_activity - The activity to start.
    - app_wait_package - Begin automation after this package starts (optional).
    - app_wait_activity - Begin automation after this activity starts (optional).
    - intent_action - Intent to start (optional).
    - intent_category - Intent category to start (optional).
    - intent_flags - Flags to send to the intent (optional).
    - optional_intent_arguments - Optional arguments to the intent (optional).
    - stop_app_on_reset - Should the app be stopped on reset (optional)?
   driver.start_activity(app_package, app_activity)

27.lock lock(self, seconds):
Lock the device for a certain period of time. iOS only.
            iOS  
    :Args:
     - the duration to lock the device, in seconds
   driver.lock()

28.shake shake(self):
Shake the device.
     
   driver.shake()

29.open_notifications open_notifications(self):
Open notification shade in Android (API Level 18 and above)
API 18 
   driver.open_notifications()

30.network_connection network_connection(self):
Returns an integer bitmask specifying the network connection type.
    Android only.
          
    Possible values are available through the enumeration `appium.webdriver.ConnectionType`

   driver.network_connection

31. set_network_connection set_network_connection(self, connectionType):
Sets the network connection type. Android only.
    Possible values:
        Value (Alias)      | Data | Wifi | Airplane Mode
        -------------------------------------------------
        0 (None)           | 0    | 0    | 0
        1 (Airplane Mode)  | 0    | 0    | 1
        2 (Wifi only)      | 0    | 1    | 0
        4 (Data only)      | 1    | 0    | 0
        6 (All network on) | 1    | 1    | 0
    These are available through the enumeration `appium.webdriver.ConnectionType`
          
    :Args:
     - connectionType - a member of the enum appium.webdriver.ConnectionType

       from appium.webdriver.connectiontype import ConnectionType
dr.set_network_connection(ConnectionType.WIFI_ONLY)
ConnectionType    
NO_CONNECTION = 0
AIRPLANE_MODE = 1
WIFI_ONLY = 2
DATA_ONLY = 4
ALL_NETWORK_ON = 6

32. available_ime_engines available_ime_engines(self):
Get the available input methods for an Android device. Package and activity are returned (e.g., ['com.android.inputmethod.latin/.LatinIME'])
    Android only.
            
  print(driver.available_ime_engines)

33.is_ime_active is_ime_active(self):
Checks whether the device has IME service active. Returns True/False.
    Android only.
/
  
   print(driver.is_ime_active())

34.activate_ime_engine activate_ime_engine(self, engine):
Activates the given IME engine on the device.
    Android only.
                 ,          “available_ime_engines
    :Args:
     - engine - the package and activity of the IME engine to activate (e.g.,
        'com.android.inputmethod.latin/.LatinIME')

   driver.activate_ime_engine(com.android.inputmethod.latin/.LatinIME)

35.deactivate_ime_engine deactivate_ime_engine(self):
Deactivates the currently active IME engine on the device.
    Android only.
            
   driver.deactivate_ime_engine()

36.active_ime_engine active_ime_engine(self):
Returns the activity and package of the currently active IME engine (e.g.,
    'com.android.inputmethod.latin/.LatinIME').
    Android only.
              
   driver.active_ime_engine

37. toggle_location_services toggle_location_services(self):
Toggle the location services on the device. Android only.
              
   driver.toggle_location_services()

38.set_location set_location(self, latitude, longitude, altitude):
Set the location of the device
            
    :Args:
     - latitude   - String or numeric value between -90.0 and 90.00
     - longitude   - String or numeric value between -180.0 and 180.0
     - altitude    - String or numeric value
   driver.set_location(  ,  ,  )

39.tag_name tag_name(self):
This element's ``tagName`` property.
     tagName  
       class name
   element.tag_name()


40.text text(self):
The text of the element.
            
   element.text()

41.click click(self):
Clicks the element.
      
   element.click()

42.submit submit(self):
Submits a form.
        
     

43.clear clear(self):
Clears the text if it's a text entry element.
           
   element.clear()


44.get_attribute get_attribute(self,name):詳細は@chenhengjie 123のスーパーリンクを参照
Gets the given attribute or property of the element.
1 content-desc      get_attribute("name")  content-desc content-desc        text 
2get_attribute         uiautomatorviewer  get_attribute         ):


name(   content-desc   text)
text(   text)
className(   class API=>18     )
resourceId(   resource-id API=>18     )
    This method will first try to return the value of a property with the
    given name. If a property with that name doesn't exist, it returns the
    value of the attribute with the same name. If there's no attribute with
    that name, ``None`` is returned.

    Values which are considered truthy, that is equals "true" or "false",
    are returned as booleans.  All other non-``None`` values are returned
    as strings.  For attributes or properties which do not exist, ``None``
    is returned.

    :Args:
        - name - Name of the attribute/property to retrieve.

    Example::

        # Check if the "active" CSS class is applied to an element.
        is_active = "active" in target_element.get_attribute("class")
     

45.is_selected is_selected(self):
Returns whether the element is selected.

    Can be used to check if a checkbox or radio button is selected.


   element.is_slected()

46.is_enabled is_enabled(self):
Returns whether the element is enabled.
            True of False
   element.is_enabled()

47.find_element_by_id find_element_by_id(self, id_):
Finds element within this element's children by ID.
         ID    
    :Args:
        - id_ - ID of child element to locate.
   driver. find_element_by_id(“id”)


48. find_elements_by_id find_elements_by_id(self, id_):
Finds a list of elements within this element's children by ID.
        ID  ,          
    :Args:
        - id_ - Id of child element to find.
   driver. find_elements_by_id(“id”)


49. find_element_by_name find_element_by_name(self, name):
Finds element within this element's children by name.
         Name  (       text)
    :Args:
        - name - name property of the element to find.
   driver.find_element_by_name(“name”)


50. find_elements_by_name find_elements_by_name(self, name):
Finds a list of elements within this element's children by name.
        Name  (       text),          
    :Args:
        - name - name property to search for.
   driver.find_element_by_name(“name”)


51. find_element_by_link_text find_element_by_link_text(self, link_text):
Finds element within this element's children by visible link text.
                
    :Args:
        - link_text - Link text string to search for.
   driver.find_element_by_link_text(“text”)


52. find_elements_by_link_text find_element_by_link_text(self, link_text):
 Finds a list of elements within this element's children by visible link text
                ,          
    :Args:
        - link_text - Link text string to search for.
   driver.find_elements_by_link_text(“text”)


53. find_element_by_partial_link_text find_element_by_partial_link_text(self, link_text):
Finds element within this element's children by partially visible link text.
                  
    :Args:
        - link_text - Link text string to search for.
driver. find_element_by_partial_link_text(“text”)


54. find_elements_by_partial_link_text find_elements_by_partial_link_text(self, link_text):
Finds a list of elements within this element's children by link text.
                  ,          
    :Args:
        - link_text - Link text string to search for.
driver. find_elements_by_partial_link_text(“text”)


55. find_element_by_tag_name find_element_by_tag_name(self, name):
Finds element within this element's children by tag name.
        html         
    :Args:
        - name - name of html tag (eg: h1, a, span)
    driver.find_element_by_tag_name(“name”)


56. find_elements_by_tag_name find_elements_by_tag_name(self, name):
Finds a list of elements within this element's children by tag name.
       html           
    :Args:
        - name - name of html tag (eg: h1, a, span)
  driver.find_elements_by_tag_name(“name”)


57. find_element_by_xpath find_element_by_xpath(self, xpath):
Finds element by xpath.
      Xpathhttp://www.w3school.com.cn/xpath/
    :Args:
        xpath - xpath of element to locate.  "//input[@class='myelement']"

    Note: The base path will be relative to this element's location.

    This will select the first link under this element.

    ::

        myelement.find_elements_by_xpath(".//a")

    However, this will select the first link on the page.

    ::

        myelement.find_elements_by_xpath("//a")

   find_element_by_xpath(“//*”)


58. find_elements_by_xpath find_elements_by_xpath(self, xpath):
Finds elements within the element by xpath.

    :Args:
        - xpath - xpath locator string.

    Note: The base path will be relative to this element's location.

    This will select all links under this element.

    ::

        myelement.find_elements_by_xpath(".//a")

    However, this will select all links in the page itself.

    ::

        myelement.find_elements_by_xpath("//a")

  find_elements_by_xpath(“//*”)


59. find_element_by_class_name find_element_by_class_name(self, name):
Finds element within this element's children by class name.
        class name      
    :Args:
        - name - class name to search for.
   driver. find_element_by_class_name(“android.widget.LinearLayout”)


60. find_elements_by_class_name find_elements_by_class_name(self, name):
Finds a list of elements within this element's children by class name.
        class name              
    :Args:
        - name - class name to search for.
   driver. find_elements_by_class_name(“android.widget.LinearLayout”)


61. find_element_by_css_selector find_element_by_css_selector(self, css_selector):
Finds element within this element's children by CSS selector.
      CSS       
    :Args:
        - css_selector - CSS selctor string, ex: 'a.nav#home'

62.send_keys send_keys(self, *value):
Simulates typing into the element.
    appium          appium    ,       )
    :Args:
        - value - A string for typing, or setting form fields.  For setting
        file inputs, this could be a local file path.

    Use this to send simple key events or to fill out form fields::

        form_textfield = driver.find_element_by_name('username')
        form_textfield.send_keys("admin")

    This can also be used to set file inputs.

    ::

        file_input = driver.find_element_by_name('profilePic')
        file_input.send_keys("path/to/profilepic.gif")
        # Generally it's better to wrap the file path in one of the methods
        # in os.path to return the actual path to support cross OS testing.
        # file_input.send_keys(os.path.abspath("path/to/profilepic.gif"))
driver.element.send_keys(“  ”)

63. is_displayed is_displayed(self):
Whether the element is visible to a user.    
         。                       (   Seleniumappium False

   driver.element.is_displayed()

64. location_once_scrolled_into_view location_once_scrolled_into_view(self):
 """THIS PROPERTY MAY CHANGE WITHOUT WARNING. Use this to discover
    where on the screen an element is so that we can click it. This method
    should cause the element to be scrolled into view.

    Returns the top lefthand corner location on the screen, or ``None`` if
    the element is not visible.
          
    """

65.size size(self):
The size of the element.
       (   )

new_size["height"] = size["height"]
new_size["width"] = size["width"]

   driver.element.size

66. value_of_css_property value_of_css_property(self, property_name):
The value of a CSS property.
CSS  

      

67.location location(self):
The location of the element in the renderable canvas.
              

   driver.element.location
'''  element x  , int  '''
driver.element.location.get('x')
'''  element y  , int  '''
driver.element.location.get('y')

68.rect rect(self):
A dictionary with the size and location of the element.
               

69. screenshot_as_base64 screenshot_as_base64(self):
    Gets the screenshot of the current element as a base64 encoded string.
              Base64      
    :Usage:
        img_b64 = element.screenshot_as_base64

70.execute_script execute_script(self, script, *args):
    Synchronously Executes JavaScript in the current window/frame.
     / Html   iframe  javascript 5 javascript     
    :Args:
     - script: The JavaScript to execute.
     - \*args: Any applicable arguments for your JavaScript.

    :Usage:
        driver.execute_script('document.title')

71.execute_async_script execute_async_script(self, script, *args):
    Asynchronously Executes JavaScript in the current window/frame.
   javascript   ,        ,            5 ,         ,      javascript         
    :Args:
     - script: The JavaScript to execute.
     - \*args: Any applicable arguments for your JavaScript.

    :Usage:
        driver.execute_async_script('document.title')

72.current_url current_url(self):
    Gets the URL of the current page.
    
    :Usage:
        driver.current_url
   driver.current_url

73. page_source page_source(self):
    Gets the source of the current page.
    
    :Usage:
        driver.page_source

74.close close(self):
    Closes the current window.
          
    :Usage:
        driver.close()

75.quit quit(self):
    Quits the driver and closes every associated window.
                      
    :Usage:
        driver.quit()
クリックしてリンクを開く