zoukankan      html  css  js  c++  java
  • APP 定位防止页面未跳转导致元素无法定位 -android特有的wait_activity

    wait_activity(self, activity, timeout, interval=1):
    
        等待指定的activity出现直到超时,interval为扫描间隔1秒
    
        即每隔几秒获取一次当前的activity
        
        android特有的
    
        返回的True 或 False
    
        :Agrs:
    
         - activity - 需等待的目标 activity
    
         - timeout - 最大超时时间,单位是s
    
         - interval - 循环查询时间
    
        用法:driver.wait_activity(‘.activity.xxx’,5,2)
    import time
    from appium import webdriver
    
    desired_caps = {
                    'platformName': 'Android',
                    'deviceName': '30d4e606',
                    'platformVersion': '7.1.2',
                    'appPackage': 'io.appium.android.apis',
                    'appActivity': '.ApiDemos',
                    'unicodeKeyboard': True,
                    'resetKeyboard': True,
                    'noReset':True,
                    "chromedriverExecutable" : "D:\driverschromedriver.exe"
                    }
    driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
    # 休眠五秒等待页面加载完成
    time.sleep(2)
    print(driver.contexts)
    driver.find_element_by_android_uiautomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("Views").instance(0))').click()
    driver.find_element_by_android_uiautomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("WebView").instance(0))').click()
    print(driver.current_activity)
    #等待activity出现,最多等20秒
    driver.wait_activity('.view.WebView1',20)
    
    print(driver.contexts)
    #获取当前页面上下文
    contexts=driver.contexts
    #切进native 进行操作
    driver.switch_to.context(contexts[1])
    driver.find_element_by_id("i_am_a_textbox").send_keys("hahah")
    time.sleep(1)
    # driver.find_element_by_id("i am a link").click()
    # 切回native
    driver.switch_to.context(contexts[0])
    title = driver.find_element_by_xpath("//android.widget.TextView[@text='Views/WebView']").text
    print(title)
    
    # driver.tap([(1,2),(3,4)],500)
  • 相关阅读:
    原生js实现 table表格列宽拖拽
    vue.js 利用SocketCluster实现动态添加数据及排序
    angular-websocket.js 使用
    判断当前页面是否是激活状态。
    remove ---会报错discard不会报错
    .pop ----remove 删除
    add添加
    #将相同值输出,取一个值
    集合
    __delattr__\__delitem__
  • 原文地址:https://www.cnblogs.com/lexus168/p/13941282.html
Copyright © 2011-2022 走看看