3.appium定位方法

1.使用id定位:

    driver.find_element_by_id('id的名称').click()

2.使用className定位:

    driver.find_element_by_class_name('元素的classname')

    注:如有多个相同的className,可使用下标进行操作

    elements=element.find_elements_by_class_name('元素的classname')

    elements[2].click()

    也可进行层级定位:

    element=driver.find_element_by_class_name('元素上一级classname')

    elements=element.find_elements_by_class_name('元素的classname')

    elements[2].click()

3.使用UIAutomator进行定位:

     driver.find_element_by_android_uiautomator('new UISelector().text("用户名")').send_keys('需要输入的信息')

4.使用xpath进行定位:

   driver.find_element_by_xpath('//*[contains(@text,"忘记密码")]').click()

   注:xpath教程:http://www.w3school.com.cn/xpath/xpath_intro.asp

5.原生app和H5进行相互切换:

   dirver.contexts   查看所有可切换的页面信息

  

   driver.switch_to.context('') 括号里填写的是你想要切换的那个页面,切换H5就写H5的,切换APP就写NATIVE_APP

6.获取tost元素:

   需要python以下模块:

      WebDriverWait

      expected_conditions

      tost_element=("xpath",'//*[contains(@text,"忘记密码")]')

      WebDriverWait(driver,10,0.1).until(expected_conditions.presence_of_element_located(tost_element))

原文地址:https://www.cnblogs.com/lixiaoting/p/11209184.html